C++ function exported in dll and loaded from C#
I have in C++:
void __declspec(dllexport) foo(HWND wnd)
And in C#
[DllImport("MyDll.dll", CharSet = CharSet.Ansi)] public static extern void foo(IntPtr wnd);
When I'm trying to call it I have this error - Additional information: Unable to find an entry point named 'foo' in DLL. I tried to inspect t开发者_运维百科he dll and I have the function with the fallowing definition:
Undecorated C++ Function: void cdecl foo(struct HWND *)
I searched on several forums and is seems that this is the right way to do this... Do you know why I have this run time error?
You need to disable C++ name mangling. Declare your native function like this:
extern "C" __declspec(dllexport) void foo(HWND wnd)
You can use the dumpbin.exe utility to see DLL exports as well.
精彩评论