12

I have written a .dll library with lots of functions and classes in visual studio 2010. When I look at the content of the file with:

dumpbin.exe /EXPORTS myDll.dll

I get long function names with some kind of a function location pointer, which looks like this (second entry in .dll):

          2    1 0001100A ?Initialize@codec@codecX@@SANNN@Z = @ILT+5(?Initialize@codec@codecX@@SANNN@Z)

This is somehow hard to read, but I saw "nicer" procedure/function list from other .dll-s, like this:

141   8C 00002A08 PogoDbWriteValueProbeInfo

How can I make that .dll list look that way?

P.S.: my dll source code looks like this:

namespace codecX
{
   class codec
   {
      public:
      static __declspec(dllexport) double Initialize(double a, double b);
      ...
Jonathan Leffler
  • 666,971
  • 126
  • 813
  • 1,185
TomiL
  • 597
  • 2
  • 10
  • 23
  • 1
    Are you sure you want to export unmangled names? If you do that then you won't be able to use function overloading. It looks like you are exporting a C++ class. Are you exporting instance methods, constructors etc. Or are all your methods static? – David Heffernan Feb 26 '13 at 13:25
  • 1
    http://stackoverflow.com/questions/2804893/c-dll-export-decorated-mangled-names – David Brabant Feb 26 '13 at 13:25
  • David H., yes my intention was to export human-readable format. Why? I need to pass created .dll to other co-workers and having readable format is essential for good understanding of source code and/or libraries written by someone else. :) – TomiL Feb 26 '13 at 17:36

3 Answers3

10

You need to pull those static member functions into the global address space and then wrap them with extern "C". This will suppress the C++ name mangling and instead give you C name mangling which is less ugly:

extern "C" __declspec(dllexport) Initialize(double a, double b)
{
    codec::Initialize(a, b);
}

and then remove the __declspec(dllexport) on your static member functions:

class codec
{
    public:
        static double Initialize(double a, double b);
}
John Källén
  • 6,905
  • 27
  • 50
4

This is called name-mangling and happens when you compile C++ with a C++-compiler. In order to retain the "humand-readable" names you'll have to use extern "C" when declaring and defining your classes and your functions. i.e.

extern "C" void myFunction(int, int); 

See here and also google mixing C and C++.

bash.d
  • 12,357
  • 2
  • 24
  • 37
0

What you are seeing is C++ mangling of function names.

In case this function needs to be kept as a C++ function you can post process the dumpbin.exe output to obtain the normal function name using the utility undname.exe.

Supplied with Microsoft Visual Studio is a utility for undecorating C++ mangled function names called undname.exe.

It can be used as follows:

C:\>undname ?func1@a@@AAEXH@Z
Microsoft (R) C++ Name Undecorator
Copyright (C) Microsoft Corporation. All rights reserved.

Undecoration of :- "?func1@a@@AAEXH@Z"
is :- "private: void __thiscall a::func1(int)"
Ayman Salah
  • 868
  • 10
  • 31