I'm building a C program which explicitly dynamically loads DLLs as part of a plugin system. I'm using GCC with MinGW on Windows 7.
What calling convention should the exported functions in the DLLs use, in order to be as robust as possible: run successfully on different Windows machines, survive different compiler versions, etc.
I know that the main executable and the DLLs need only use the same calling convention. How is this normally managed?
Currently I'm only aiming at supporting Windows (even though answers referring also to the same subject on Linux will be welcome as well).
EDIT:
Please let me clarify the question, as discussed in a comment section with @S. S. Anne.
I'm less concerned about the particular calling convention. I'm more concerned with what is the standard way to ensure compatibility between a binary built on machine X and a DLL (plugin thing) built by somebody else on machine Y, which might have a different OS etc.
One approach I can think of, is that in the header file distributed to plugin developers, we define a macro that specifies the expected calling convention of functions exposed by the plugin to the main program. These functions will be defined by the plugin developer using this macro.
For example, the api.h
header, supplied to plugin developers, defines #define CALL __cdecl
. And after doing #include "api.h"
, the exported functions in the plugin DLL are declared like so: void CALL func(void);
.
Is this solution used in practice? Are there different approaches?