[英]Get functions mangled name from C++ DLL
I have function declared as __declspec(dllexport) void TakeInput();
我有 function 声明为
__declspec(dllexport) void TakeInput();
The DLL which has this function is exported in C#.I am getting failure while executing function call to this function as entry point not found in c# code. The DLL which has this function is exported in C#.I am getting failure while executing function call to this function as entry point not found in c# code.
Googling shows that issue is with correct entry point is not provided.I will need to provide mangled name for this function.谷歌搜索显示问题是没有提供正确的入口点。我需要为此 function 提供错误名称。
So I would like to know how can I get mangled name of this function?所以我想知道我怎样才能得到这个 function 的损坏名称?
in order to avoid name mangling, use extern "C"
为了避免名称混淆,请使用
extern "C"
extern "C" __declspec(dllexport) void TakeInput();
More reading: Using extern to specify linkage更多阅读:使用外部指定链接
You can use DependancyWalker (http://www.dependencywalker.com) or some other tool that lists DLL exports to get the mangled name if you really want to, but you're best doing what Armen suggested.您可以使用 DependancyWalker (http://www.dependencywalker.com) 或其他列出 DLL 导出的工具来获取损坏的名称,但您最好按照 Armen 的建议进行操作。
Instead of trying to compute the mangled name, I suggest to just export the unmangled name.我建议不要尝试计算损坏的名称,而是只导出未损坏的名称。 Do do this, you need to do two things:
这样做,你需要做两件事:
Disable C++ name mangling by using C linkage for your function You can do this by using extern "C"
.通过使用 function 的 C 链接来禁用 C++ 名称修改您可以使用
extern "C"
来执行此操作。
Ensure that your function is using the C calling convention.确保您的 function 使用 C 调用约定。 This is the default (at least with Microsoft Visual Studio) but this default can be changed using the
/Gr
(which toggles the __fastcall
calling convention) and /Gz
(which toggles the __stdcall
calling convention) command line switches.这是默认值(至少在 Microsoft Visual Studio 中),但可以使用
/Gr
(切换__fastcall
调用约定)和/Gz
(切换__stdcall
调用约定)命令行开关更改此默认值。 You can enforce the C calling convention using __cdecl
like this:您可以使用
__cdecl
执行 C 调用约定,如下所示:
So all in all, to ensure that your function is exported as TakeInput
, use:总而言之,要确保您的 function 导出为
TakeInput
,请使用:
extern "C" __declspec(dllexport) void __cdecl TakeInput();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.