How to remove the underscore from DLL export

2k Views Asked by At

I want to replace a DLL for which I don't have the full source code (but the function declarations). The application loads this DLL at runtime and calls GetProcAddress with (all) the function names. (so I have to name the functions exactly the same).

I created a new DLL (in MS VC2013) and wrote the functions. But I have a problem exporting them correctly.

In the original DLL they are defined with _stdcall but their names don't start with an underscore.

If I specify the name in the .def file like this testfunc@4=testfunc everything behind the @ is removed.

How can I specify in VS2013 that I want an DLL-export like testfunc@4?

1

There are 1 best solutions below

1
Uga Buga On

The easiest way I think is by adding

// in cpp, but will probably work in header too
#pragma comment(linker, "/export:FunctionName@4=_FunctionName@4")

// in header
extern "C" __declspec(dllexport) void __stdcall FunctionName(int param);

in the source code of your DLL.

I got the idea from here. They also explain how to do it with a DEF file. A matter of taste I guess. You will end up with two entries for the same function in the export table but the application should be able to get the correct proc address.