使用 extern c 和 dllexport 与模块定义 (msvc++) 进行 stdcall 名称修改 [英] stdcall name mangling using extern c and dllexport vs module definitions (msvc++)

查看:36
本文介绍了使用 extern c 和 dllexport 与模块定义 (msvc++) 进行 stdcall 名称修改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图为 dll 导出一个简单的测试函数,以便与指定调用约定的应用程序(仅供参考:mIRC)一起使用:

int __stdcall test_func(HWND mWnd, HWND aWnd, char *data, char *parms, BOOL show, BOOL nopause)

现在,要从应用程序调用它,我将使用 test_func 但我注意到由于名称修改,它并不像我想象的那么简单.

通过这里的类似主题,我了解到将 extern "C"__declspec(dllexport) 结合使用是一种消除重整的等效(有点)方法到模块定义 (.def).但是,当使用 extern/dllexport 方法时,我的函数(作为示例)始终是 _test_func@numbers 而 .def 删除了我需要导出到的应用程序所需的所有重整.>

谁能解释一下这是为什么?我只是对这两种方法很好奇.谢谢!

解决方案

dllexport/import 被设计为自己加载回来,而不是使用 GetProcAddress 的旧 C 库.您所看到的重整是所有 Microsoft 编译器长期以来对 __stdcall 函数所做的.最有可能的是,您的目标需要一个 __cdecl 函数,而不是 __stdcall,但如果没有,您将需要使用 .def 文件来专门取消对名称的处理.

I was trying to export a simple test function for a dll to work with an application (fyi: mIRC) that specifies the calling convention as:

int __stdcall test_func(HWND mWnd, HWND aWnd, char *data, char *parms, BOOL show, BOOL nopause)

Now, to call this from the application, I'd be using test_func but I have noticed due to name mangling it is not as simple as I'd thought.

Through similar topics here I have come to the understanding that using extern "C" in combination with __declspec(dllexport) is an equivelant (somewhat) method of removing mangling to module definitions (.def). However, when using the extern/dllexport method my function (as an example) is always _test_func@numbers whereas the .def removed all mangling as required for use with the application i needed to export to.

Could someone please explain why this is? I'm just curious about the two methods. Thanks!

解决方案

dllexport/import are designed to be loaded back by themselves, not an old C library using GetProcAddress. The mangling you have seen is what all Microsoft compilers have done for a long time for __stdcall functions. Most likely, your target either expects a __cdecl function, not __stdcall, but if not, you will need to use a .def file to specifically un-mangle the name.

这篇关于使用 extern c 和 dllexport 与模块定义 (msvc++) 进行 stdcall 名称修改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆