Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

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

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top