开发者

C++ function exported in dll and loaded from C#

开发者 https://www.devze.com 2023-02-07 07:43 出处:网络
I have in C++: void __declspec(dllexport) foo(HWND wnd) And in C# [DllImport(\"MyDll.dll\", CharSet = CharSet.Ansi)]

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消