Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

__cdecl forcing prefix with underscore

My company provides a third party with a DLL which provides them with API functions they can use to connect to our application. The DLL was written in VC9, and the API functions used VC's default calling convention (__cdecl). The third party has built their application around this interface.

I have now been tasked with writing an updated version of the DLL. We want the DLL to have exactly the same interface as the old one so they can be used interchangeably. Unfortunately, our development environment is now CodeGear RAD Studio 2007, so I have to write the DLL using that.

The best solution would be to make both the old and new DLLs export their functions as __stdcall. The third-party application could then be re-linked to expect __stdcall functions and everyone would be happy. Unfortunately, for various reasons this is unlikely to happen.

Alternatively, I can declare the functions in my DLL as __cdecl. The third-party expects __cdecl functions so this would seem to be a good solution. Unfortunately CodeGear insists on appending an underscore ('_') to the name of __cdecl functions. This means that the third-party application would have to make conditionally call MyApiFunction(...) or _MyApiFunction(...), depending on which DLL they use.

So my question is, how can I export the API functions from my new DLL in such a way that they are __cdecl and are not prefixed with an underscore ('_')?

like image 607
Hoppy Avatar asked May 13 '11 06:05

Hoppy


People also ask

What is__ cdecl in c++?

The __cdecl function specifier (C++ only) The __cdecl keyword instructs the compiler to read and write a parameter list by using C linkage conventions. To set the __cdecl calling convention for a function, place the linkage keyword immediately before the function name or at the beginning of the declarator.

What does cdecl mean in C?

The cdecl (which stands for C declaration) is a calling convention that originates from Microsoft's compiler for the C programming language and is used by many C compilers for the x86 architecture. In cdecl , subroutine arguments are passed on the stack.

How does cdecl work?

In CDECL arguments are pushed onto the stack in revers order, the caller clears the stack and result is returned via processor registry (later I will call it "register A"). In STDCALL there is one difference, the caller doeasn't clear the stack, the calle do. You are asking which one is faster.


1 Answers

You should use .DEF file:

EXPORTS
    HTMLayoutClassNameA = HTMLayoutClassNameA
    HTMLayoutClassNameW = HTMLayoutClassNameW
    HTMLayoutClipboardCopy = HTMLayoutClipboardCopy
    ...

Here we have

externalname = internalname 
like image 179
c-smile Avatar answered Oct 16 '22 07:10

c-smile