In C++,

extern "C"
    __declspec(dllexport) int test(char* data);
__declspec(dllexport) int test(char* data)
    string str = "wassup";
    strcpy(data, str.c_str());
    return 1;

In C#

[DllImport(dll, CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
static extern int test(StringBuilder faceData);

static public void testDll()
        StringBuilder ASMData = new StringBuilder(500);
    catch (Exception e)

I have been doing this kind of job so many times and I have working dll's in my folder but the problem I currently have is really weird. I think it might be a bug of C# or Windows.

As you can see the code above, it is very simple, easy and straightforward. C# should print "wassup" on the console.
But this is how it works:

1st run => works fine.
2nd run with same built objects (no change in code) => works fine.
3rd run with newly built objects (rebuil without any code change) => Unable to find an entry point named 'test' in dll
copy new dll
4th run with previously built objects => works fine.

Once the program is run, I think dll file is stuck in the memory even though the program is terminated.

What do you guys think and what should I do to fix it?

Edited by 9tontruck

4 Years
Discussion Span
Last Post by 9tontruck

Did you check that the file still exists in the output folder of your build? Visual Studio could be deleting the DLL because you're doing a rebuild. (Performs a 'Clean' step)


Dayum.. it was really stupid of me. Thd old dll that was included in the solution kept being copied into bin folder. Thanks for the advice!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.