## C++Builder Define DLL Export Function Names Using DEF File

Recently, I've been working on looking for the way to customize dll export function names in C++Builder.
There are several methods to achieve this in VC++, including using a .def file, using __declspec keyword, and using an /EXPORT specification in a LINK command.
The third way seems not to be supported by bcc32 compiler (aka Borland C++ compiler), so I've researched on the implementation of the prior two methods.

First, I use __declspec(dllexport) keyword with specifying different calling conventions to export the functions below.

If we look up our code in a disassembler, we'll find that all of these functions have the same operation code like below.

And let me use impdef tool to list all the export functions to a def file.

impdef TestDll.def TestDll.dll

The result shows that whether we use extern "C" or not, the effect of functions using __cdecl are the same.
The reason is that it is the default calling convention for C and C++ programs.
(@1 with @4 and @5 with @8)
And this setting can be found in Project Options.

So if we modify our TestDll.def like this:

and put it into the project then do a compile, cheer! We make it!

Let me orginize the result into tables:

void FUNCTION_NAME()

C/C++ __cdecl __stdcall __fastcall
extern "C" ＿FUNCTION_NAME FUNCTION_NAME @FUNCTION_NAME
@FUNCTION_NAME$qv @FUNCTION_NAME$qqsv @FUNCTION_NAME\$qqrv

After all, we can now export __declspec(naked) function in this way!
Since functions declared with the naked attribute, the compiler generates code without prolog and epilog code, we can have a pure assembly function and do less operations to hijack a dll. :p