Take the 2-minute tour ×

How can I find out the decorated name that will be asigned to each method name ? I'm trying to find out what the decorated name is , so that I may export it , in a DLL .

share|improve this question
add comment

6 Answers

.DEF file are still being used?

Forget .DEF files. They are a thing of the past.

Export your functions, be them C functions or C++ symbols, through __declspec(dllimport/dllexport).

If you really need undecorated names, use as suggested by Greg Hewgill, the __declspec(dllimport/dllexport) keywords, combined with extern "C", which will strip those symbols of their decoration...

Are you sure you want to remove the C++ decoration?

There are some valid reasons for that: You want to export code that will be used by C code, or you want to use your DLL from modules compiled with different compilers.

And for the second reason, I would instead produce one DLL per compiler, and keep the decorations.

Aside those reasons, why do you want the decorations removed?

C++ decorations/name mangling is not Evil

Quite the contrary.

If you are working with one compiler (and I suppose you do, because your want to use the decorated names, not extern "C" ones), then keep the C++ decoration/name mangling.

In this way, you'll be able to use full C++ power, that is, namespaces, classes, function/method overloads, etc..

Still, playing manually with symbol decorations is a recipe for disaster: Use dllexport to export your symbols without having to deal with yet another (.DEF) file.

share|improve this answer
add comment

This question is pretty similar: Exporting DLL C++ Class , question about .def file. The quick summary is that you probably want to use __declspec(dllexport) to let the compiler do the work of exporting your methods for you.

Microsoft changes the way they do function name mangling (or "decorated names" as they call them) with every compiler version, so you would probably run into future maintenance troubles if you try to manually export the mangled names. If you google for "msvc decorated names" there are some links that might help, but no guarantees.

share|improve this answer
I know that UndecorateSymbolName() exists . I wanted to know if there was some DecorateSymbolName() :) –  Vhaerun Oct 10 '08 at 6:45
The compiler itself will work for that. Look in the linker map file, for example. –  Greg Hewgill Oct 10 '08 at 7:30
add comment

Since C++ name mangling is not something that matches up between different compilers (as Greg Hewgill mentioned, it can change even between versions of the same vendor's compiler) and there is no standard binary interface for C++, it's usually not a good idea to export C++ functions from a DLL. The exception would be if the DLL is pretty much tightly bound to and versioned with the application using it.

An alternative is to have your exported functions declared as extern "C".

share|improve this answer
add comment

By using dumpbin on an object file , you will find all the methods used in the object . Here's how it's used

dumpbin /symbols File.obj
share|improve this answer
can also run against DLL –  Aidan Ryan May 18 '09 at 16:39
add comment

I think you should take the advice of the previous 2 respondants Greg Hewgill and Mike B, but if you are using the Microsoft tool chain and you really want to know the decorated name(s)...

  1. Create your .lib and .dll files using *__declspec(dllexport)*
  2. Inspect the names exported by the dll using dumpbin /exports
  3. Now you can remove the *__declspec(dllexport)* and export the symbols manually in the .def file
share|improve this answer
add comment

In VS2005, there's the preprocessor macro FUNCDNAME that returns a string with the decorated name, when placed within the function. This is, however, non standard - the C99 standard has func for that, and I can't say whether your compiler supports that.

(why o why don't the underscores show properly??)

(edit:) This apparently came up recently in a similar discussion.

share|improve this answer
add comment

Your Answer


