views:

93

answers:

3

I hope to LoadLibrary on an unmanaged C++ DLL with managed code, and then call GetProcAddress on extern functions which have been mangled. My question is are the mangled names you get from a C++ compiler deterministic? That is: Will the name always by converted to the same mangled name, if the original's signature hasn't changed?

+6  A: 

It isn't specified by the standard, and has certainly changed between versions of the same compiler in my experience, though it has to be deterministic over some fixed set of circumstances, because otherwise there would be no way to link two separately compiled modules.

If you're using GetProcAddress, it would be far cleaner to export the functions as extern "C" so their names are not mangled.

Daniel Earwicker
A particular version of a compiler will mangle names consistently, otherwise it wouldn't be able to link with things it produced. Other than that, all bets are off.
Nathan Tomkins
A: 

Name mangeling is handled differently by every compiler (maybe or not-there is no standard). If you use pure C functions in your C++ code, you can use the extern "C" to supress name mangeling for the C functions so the compiler is able to find them.

InsertNickHere
+1  A: 

It's compiler specific, as others have said. However, you can find details in a document by Agner Fog...

http://www.agner.org/optimize/#manuals

See item 5 on that page.

Also, these days, there are libraries which can handle mangling and demangling for common compilers for you. For Visual C++, the starting point would be the dbghelp and imagehlp libraries.

http://msdn.microsoft.com/en-us/library/ms679292%28v=VS.85%29.aspx

http://msdn.microsoft.com/en-us/library/ms680321%28v=VS.85%29.aspx

Steve314