I'm linking from c# to a quite complex c++ dll. I need to create a lot of dllexport funtions so I can use the dll in c#. To get started, I added a .cpp file and created a simple test function:
c++:
extern "C" __declspec(dllexport) int32_t Test(){
return 10;
}
c#:
[STAThread]
static void Main()
{
Console.WriteLine(Test());
}
[DllImport("Test.dll", EntryPoint = "Test", CallingConvention = CallingConvention.Cdecl,ExactSpelling = true)]
public static extern Int32 Test();
This test works perfectly 90% of the time and then suddenly....
The program '[4712] Test.vshost.exe' has exited with code -1073741819 (0xc0000005) 'Access violation'.
Everything seems fine, no idea what causes it or even how to begin to track down the problem. It's weird that it is so intermittent. I'm not a c++ programmer really so I've no idea what might cause this behaviour, or even how to debug and find the problem.
Hope some kind soul can help.