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

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

问题描述

我试图导出一个简单的测试函数为dll工作与应用程序(fyi:mIRC)  int __stdcall test_func(HWND mWnd,HWND aWnd,char * data,char * parms,BOOL show,BOOL nopause)

现在,从应用程序调用这个,我将使用 test_func ,但是我注意到,由于名称mangling它不是我想象的那么简单。

通过类似的主题在这里我已经认识到使用 externC结合 __ declspec(dllexport)是一种消除模块到模块定义(.def)的等价(有些)方法。但是,当使用extern / dllexport方法时,我的函数(作为一个例子)总是 _test_func @ numbers ,而.def删除了所有需要导出的应用程序所需的修改。 p>

有人可以解释为什么会这样吗?我只是好奇两种方法。谢谢!

解决方案

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.

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

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