How do I stop name-mangling of my DLL's exported function?
Solution 1:
Small correction - for success resolving name by clinet
extern "C"
must be as on export side as on import.
extern "C" will reduce name of proc to: "_GetName".
More over you can force any name with help of section EXPORTS in .def file
Solution 2:
This is normal for a DLL export with a __stdcall
convention. The @N
indicates the number of bytes that the function takes in its arguments -- in your case, zero.
Note that the MSDN page on Exporting from a DLL specifically says to "use the __stdcall calling convention" when using "the keyword __declspec(dllexport) in the function's definition".
Solution 3:
the right answer is the following:
extern "C" int MyFunc(int param);
and
int MyFunc(int param);
is two declarations which uses different internal naming, first - is in C-style, second - in the C++ style.
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 and c++ namings.
both this styles of naming is applied when using __declspec(dllexport) in the same manner.
if you want to omit name mangling of exported routine, add a module definition file to your project, type in it (in this case you not required to declspec dllexport):
LIBRARY mylib
EXPORTS
MyFunc
this will omit explicit name decoration (samples below).
_MyFunc (c style, __cdecl)
_MyFunc@4 (c style, __stdcall)
?MyFunc@@YAHH@Z (c++ style, __cdecl)
?MyFunc@@YGHH@Z (c++ style, __stdcall)
Solution 4:
You can use the "-Wl,--kill-at" linker switch to disable name mangling.
For example, in Code::Blocks, in the custom linker settings, add: -Wl,--kill-at