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
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
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:
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