DLL Linkage and Decoration

Started by
6 comments, last by GameDev.net 17 years, 9 months ago
When exporting DLL functions using "C" linkage, GetProcAddress accepts regular function names for importing. However when using "C++" linkage, does it expect decorated function names? If that is true (which am almost sure about, cost me a hell of a time, and it doesn't get mentioned in the SDK), can I programatically get the decorated name of the function. If not, how do I generally get the decorated name other than having to open the .lib file with notepad and lurking into it?
[ my blog ]
Advertisement
If you export a C++ function, then the compiler will decorate it (So you'll actually export "_MyFunctionYPAZZQ@4" or whatever. If you use extern "C", then it won't get decorated.
GetProcAddress() Will only look for the exact name you pass it; it won't try to [un]decorate it for you. There's a function in dbghlp.lib called something like UndecorateName() which will give you the function signature from a decorated name (E.g. "void MyFunction(const char*, int)", but you shouldn't need to use it in this case.

EDIT: If you're going to be using GetProcAddress(), you should really be using undecorated names anyway, since name decoration is compiler dependant.
Have your IDE generate a map for you during the linkage step.
Your compiler should also come with a tool generally named something like dump or tdumpbin or dumpbin that will allow you to examine the export table of a DLL.
I tend to use extern "C" myself, just to make it easy. That way I can just pass the function name with GetProcAddress. I don't know what that does for overloaded functions, but I do not use overloaded functions with DLLs.
"Mommy, where do microprocessors come from?"
Quote:Original post by Dreq
I don't know what that does for overloaded functions, but I do not use overloaded functions with DLLs.
It just doesn't work - the code won't compile.
Hehe, shows how many times I've done that ;)
"Mommy, where do microprocessors come from?"
extern "C" must be the very first thing on the line where the function is declared.

To see the decorated function names, type:
dumpbin /exports yourfile.exe

This topic is closed to new replies.

Advertisement