Mircea Ispas
Mircea Ispas

Reputation: 20790

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?

Upvotes: 1

Views: 1214

Answers (1)

Ed Swangren
Ed Swangren

Reputation: 124770

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.

Upvotes: 4

Related Questions