C++ name mangling hell

less than 1 minute read

I found this post on Experts exchange about C++ name mangling hell. I have run in to this problems a few times, it drives me nuts as I always forget about it when trying to use LoadLibrary and GetProcAddress.

#ifdef FIRSTINDLL_EXPORTS #define FIRSTINDLL_API extern "C" __declspec(dllexport) #else #define FIRSTINDLL_API extern "C" __declspec(dllimport) #endif // Exported function. FIRSTINDLL_API const char* const FirstGetBuf(USHORT Num); Otherwise the exported function will end up as FirstGetBuf@US&NP

In c++ they try to make all the functions have unquie names by adding a hash of something to the end of the exported function “US&NF” this works really well for creating unquie function names but it makes it impossable to use GetProcAddress. So we have to Extern C all the functions so they show up as C function instead of C++ functions.

Leave a comment