C++ name mangling hell

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.

No Comments.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>