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()
{
try
{
StringBuilder ASMData = new StringBuilder(500);
test(ASMData);
Console.WriteLine(ASMData);
}
catch (Exception e)
{
Console.WriteLine(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?