English 中文(简体)
我如何停止对我的利比里亚国防部队的出口职能进行名称管理?
原标题:How do I stop name-mangling of my DLL s exported function?
  • 时间:2009-09-23 16:26:04
  •  标签:

我试图建立一个DL,输出一个称为“GetName”的职能。 我同其他守则一样,能够称呼这一职能,而不必知道人名。

我的主人认为:

#ifdef __cplusplus
#define EXPORT extern "C" __declspec (dllexport)
#else
#define EXPORT __declspec (dllexport)
#endif

EXPORT TCHAR * CALLBACK GetName();

我的法典认为:

#include <windows.h>
#include "PluginOne.h"

int WINAPI DllMain (HINSTANCE hInstance, DWORD fdwReason, PVOID pvReserved)
{
     return TRUE ;
}

EXPORT TCHAR * CALLBACK GetName()
{
    return TEXT("Test Name");
}

在我办公时,DL仍然以“GetName@0”的名义出口这一功能。

我做了什么错误?

最佳回答

小型纠正——通过热线成功解决名字

extern "C"

必须像进口一样在出口方面。

外部“C”将减少原名:“GetName”。

更不用说,你可以在进出口公司帮助下用任何名字。

问题回答

持有<条码>----------------->公约的DLL出口通常如此。 The @N rel=“noreferer”>indicatess number of bytes that the function take in its debate - in You case,0.

注:.MSDN page on Exporting from a DLL specified to "the keyword declspec(dllexport) in the function s definition”。

正确的答案如下:

extern "C" int MyFunc(int param);

以及

int MyFunc(int param);

两项声明使用不同的内部命名,首先是C类,其次是C++类。

internal naming required for build tools to determine which arguments function receives, what type returns etc, since C++ is more complicated (oop s, overloaded, virtual functions etc) - it uses more complicated naming. calling convention also affects both c 以及 c++ namings.

在使用dec(出口)时,采用这种命名方式。

如果你想要删除出口例行公事的名称,在项目类型上添加一个单元定义文件(在这种情况下,你不需要去除出口物):

LIBRARY mylib
EXPORTS
  MyFunc

这将排除明确的名称评分(下文各册)。

_MyFunc (c style, __cdecl)
_MyFunc@4 (c style, __stdcall)
?MyFunc@@YAHH@Z (c++ style, __cdecl)
?MyFunc@@YGHH@Z (c++ style, __stdcall)

你们可以使用“Wl,-技能-at”连接器转换为可调取的名称。

For example, in Code::Blocks, in the custom linker settings, add: -Wl,--kill-at





相关问题
热门标签