In my code, I can load "MessageBoxA" from user32.dll and use it, but if I try to load and use a function from my DLL, I get a crash.
My C# code:
[DllImport("SimpleDLL.dll")]
static extern int mymean(int a, int b, int c);
[DllImport("user32.dll")]
static extern int MessageBoxA(int hWnd,
string msg,
string caption,
int type);
[...]
this works
MessageBoxA(0, "Hello, World!", "This is called from a C# app!", 0);
this crashes
int mean = mymean(12, 14, 16);
And my C++ DLL code: SimpleDLL.cpp:
extern "C" _declspec(dllexport) int mymean(int x, int y, int z)
{
return (x + y + z) / 3;
}
SimpleDLL.def:
LIBRARY "SimpleDLL"
mymean
SimpleDLL.dll is copied to the same folder as the .exe I compile from C# code. Using dependency walker, I can see that all necessary DLLs to load SimpleDLL.dll are present.