Eric Lindgren
Eric Lindgren

Reputation: 31

C/C++ mangle exports in a specific way

Due to specific needs i need to create a DLL which exports a function that is named in a specific way, it's also mangled.

?drawGdi@stop@234@@Z

Is there anyway of accomplishing this?

Upvotes: 0

Views: 170

Answers (2)

Can't you declare your function like e.g.

 class myclass;
 extern "C" void my_function(int,myclass&);

Then it should be exported as my_function (at least on Posix systems; I guess it is the same on Windows, but I don't know).

If compiling with GCC, you could use Asm Labels. Then any name acceptable by the assembler should be ok.

On Linux with ELF executables you probably could not, as David Schwartz suggested, simply edit the binary file (because that would probably break some hash-table used in ELF for symbols).

Upvotes: 1

rodrigo
rodrigo

Reputation: 98398

You can do that, but you have to write a DEF file.

foo.h:

extern "C" declspec(dllexport) void foo(int);

foo.def:

EXPORTS
    ?drawGdi@stop@234@@Z=_foo

(_foo is the exported name of the function).

Remember to specify the DEF file when linking the DLL, of course.

For more details see the documentation on DEF files.

Upvotes: 2

Related Questions