DUMPBIN utility mangled name output

眉间皱痕 提交于 2019-12-10 15:20:58

问题


I am using DUMPBIN utility for getting mangled name from a c++ dll to use in a c# application . I am exposing a c++ class member function using __declspec(dllexport) and the output mangled name result is the folowing

?InitPort@CProtocolStack@@QAEEHEPAEKE@Z = ?InitPort@CProtocolStack@@QAEEHEPAEKE@Z (public: unsigned char __thiscall CProtocolStack::InitPort(int,unsigned char,unsigned char *,unsigned long,unsigned char))

Do I need to use the whole name in C# application while importing the same function ? If not, which part will be sufficient for importing?


回答1:


You just need this bit:

?InitPort@CProtocolStack@@QAEEHEPAEKE@Z

Then you declare it something like:

[DllImport("your.dll",
    EntryPoint = "?InitPort@CProtocolStack@@QAEEHEPAEKE@Z",
    ExactSpelling = true)]
static extern byte CProtocolStack::InitPort( /* etc. */);



回答2:


Don't. If you're not using managed C++ (which can be called directly from C#), declare the functions in your interface extern "C", then use the function name directly. Mangling can change from one version of the compiler to the next; the extern "C" names won't.



来源:https://stackoverflow.com/questions/20759324/dumpbin-utility-mangled-name-output

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!