0

I'm changing signature of a function which will be exported in dll.

DEF file:

...
??0CLimitOrderBase@Base@@QEAA@H@Z
?foo@CLimitOrderBase@Base@@UEAAHAEAVCLimitInfo@2@@Z
...

Code will change from

namespace Base {

class CLimitOrderBase : public CLimit
{
    ...
    virtual BOOL foo(CLimitInfo &limitInfo);
    ...
};

to

virtual BOOL foo(CLimitInfo &limitInfo, bool bCheck = false);

How do I get the new mangled name to change in the DEF file?

Deqing
  • 14,098
  • 15
  • 84
  • 131

2 Answers2

1

Add the following to a header file which every other header file from your DLL includes (renaming YOURDLL with something meaningful):

#ifdef YOURDLL_EXPORTS
#define YOURDLL_API __declspec(dllexport)
#else
#define YOURDLL_API __declspec(dllimport)
#endif

Then declare your exported classes as in this example:

class YOURDLL_API CLimitOrderBase : public CLimit
{
    ...
    virtual BOOL foo(CLimitInfo &limitInfo);
    ...
};

Finally, define YOURDLL_EXPORTS in your DLL project (Preprocessor Definitions field under Properties->C/C++->Preprocessor). This way you wouldn't need manual editing of .DEF file.

Serge Rogatch
  • 13,865
  • 7
  • 86
  • 158
0

Using dllexport is a good idea, but currently I'm just changing one function of a existing big DEF file, and .def vs _declspec(dllexport) is beyond this topic.

Thanks for the comment from Hans Passant, I finally figured out how to get mangled C++ function name from Visual Studio (For g++ please refer to this answer.)

  1. Generate .map file:
    • In VS, open the project's Property Pages dialog box
    • Click Linker folder
    • Click Debug property page
    • Modify Generate Map File property.
  2. Rebuild the project.
  3. Open generated .map file, search for the function name.
  4. Copy the new mangled name to .def file
Community
  • 1
  • 1
Deqing
  • 14,098
  • 15
  • 84
  • 131