Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why extern "C" still cannot remove name mangling in the following case

extern "C"
{
__declspec(dllexport) LRESULT CALLBACK MTest
}

Using depends , I found there is still name mangling even using extern "C".

like image 551
user496949 Avatar asked Dec 21 '22 16:12

user496949


2 Answers

The only way to get truly undecorated names with __declspec(dllexport) is to export them with the __cdecl calling convention. CALLBACK becomes __stdcall, which decorates the "C" form of the name with a leading _ and trailing @bytes.

Otherwise you can use a .DEF file, which is a pain. Another MSVC specific way is to embed a /EXPORT directive into the object file (or pass it as a explicit linker setting)

#pragma comment(linker, "/EXPORT:ExportSymbol=DecoratedName");

For some reason the = part of the directive is not listed in the help

like image 154
Chris Becke Avatar answered Jan 23 '23 06:01

Chris Becke


That's name decoration rather than mangling. You should declare the undecorated name in a DEF file and then you'll get the behaviour you are seeking.

like image 26
David Heffernan Avatar answered Jan 23 '23 06:01

David Heffernan