Sign in to follow this  

DLL Linkage and Decoration

This topic is 4193 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Have your IDE generate a map for you during the linkage step.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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

Share this post


Link to post
Share on other sites

This topic is 4193 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this