简体   繁体   中英

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 the 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM