Reputation: 63
I have a section of C++ code in MSVC2010 that creates a DLL wrapper. The section of code looks something like this...
extern "C" __declspec(dllexport) DWORD myDllExportFunction()
{
return (DWORD)SomeFunction(SomeParameter);
}
or...
_declspec(dllexport) int64 _stdcall myDllExportFunction2(<someType> someParameter){
{
return new (DWORD)SomeExternalFunction(SomeParameter);
}
I would expect my exports section from doing a dumpbin on this dll to contain just the fully qualified function name however it looks more like this.
_myDllExportFunction@12 = _myDllExportFunction@12
I have no idea why this equal sign is there or what it means. I have a strong feeling that the function is not accessible by programs which import the dll as it is not doing what it is supposed to.
for sake of providing enough information I have included some of my compiler and linker switches
Compiler Options:
/Zi /nologo /Wall /WX- /O2 /Ob2 /Oi /Oy- /D "_WINDLL" /D "_MBCS" /D "_AFXDLL" /Gm- /EHsc /GS /fp:precise /Zc:wchar_t /Zc
Linker Options:
/MANIFESTUAC:"level='asInvoker' uiAccess='false'" /DEBUG /PDB:"C:\....\MyProj.pdb" /SUBSYSTEM:CONSOLE /OPT:REF /OPT:ICF /PGD:"C:\....\MyProj.pgd" /TLBID:1 /DYNAMICBASE:NO /NXCOMPAT:NO /IMPLIB:"MyProj.lib" /MACHINE:X86 /ERRORREPORT:QUEUE
Note: /IMPLIB:"MyProj.lib" -> This import library has all of the exports that I want to have in my DLL in the format that I want them to be in the dll.
Is there any setting in my projects options that would cause this? Was there any changes to dllexport in the past years that I might have missed? Is there any information that I could provide you that would help you understand my problem?
Upvotes: 2
Views: 906
Reputation: 109119
There are a few different options to prevent name mangling.
Change the declaration specifier for the exported function from
__stdcall
to __cdecl
. So the function signature should look like
this
extern "C" DWORD __declspec(dllexport) __cdecl myDllExportFunction()
If you must use the __stdcall
calling convention use one of the following two methods to get around name mangling. In both cases you do not need to add __declspec(dllexport)
to the function definition (but it's OK if you do).
LIBRARY YourLibraryName
EXPORTS
myDllExportFunction
/export:myDllExportFunction
Upvotes: 0
Reputation: 283634
If you want to control the names of exported functions (for example, to remove mangling), you'll need to use a linker module definition (.def
) file.
Upvotes: 0
Reputation: 146910
You have mangled the name by declaring it __stdcall
, presumably in a separate declaration. You must give it the __cdecl
calling convention to avoid name mangling.
Upvotes: 0