Hoppy
Hoppy

Reputation: 760

How to force VC++ name mangling C++Builder?

Is it possible to export a function from a C++Builder DLL with a specific mangled name?
I am trying to build a C++Builder DLL to replace an existing VC++ DLL. The problem is that the application that uses the DLL expects one of the functions to have a specific mangled name.

That is, it expects the function to be called:

"?_FUNCTIONNAME_@@YAHPAU_PARAM1_@@PAU_PARAM2_@@@Z"

Of course I can export function from my DLL with a mangled name but CodeGear insists on using its own name mangling scheme.

Is it possible to force C++Builder to:

  1. Use a specific mangled name for a function?

    or

  2. Use VC++ name mangling for a specific function?

Note that I only want to change the mangling for a specific function, not all the functions in the DLL.

Upvotes: 0

Views: 457

Answers (2)

Remy Lebeau
Remy Lebeau

Reputation: 597051

Use a .def file to specify your own naming for the exported function.

Upvotes: 2

AProgrammer
AProgrammer

Reputation: 52314

Name mangling is just one of many aspects of the ABI. And it fact it would be the more easy to standardize. Compilers are using purposefully different name manglings when they are using different ABI in order to prevent linking incompatible objects.

One thing you may try for a given function is to mark it extern "C", then it will use the calling convention of C and the same mangling (commonly no mangling at all or just an initial _). Obviously that won't take care of other issues (handling of exceptions, precise content of vtbls, which registers are used for passing parameters, the precise definition of the standard library, ...)

Upvotes: 2

Related Questions