0

I'm trying to add an stdcall calling convention to my GNU compiled DLL.

Here is my code:

typedef void (__stdcall * CTMCashAcceptCallback) (
    const struct CTMEventInfo,
    const struct CTMAcceptEvent );

It's been called by this function:

LIBCTMCLIENT_FUNC void ctm_add_cash_accept_event_handler(CTMCashAcceptCallback);

where:

#define LIBCTMCLIENT_FUNC LIBCTMCLIENT_C_LINKAGE __declspec(dllexport) __stdcall

The problem is that it gives me this note:

note: expected 'CTMCashAcceptCallback' but argument is of type 'void (*)(const struct CTMEventInfo, const struct CTMAcceptEvent)'

When I remove the __stdcall or replace it with __cdecl instead, it does not give that information. Is it not possible to use stdcall when compiling through GNU or maybe I'm not doing it right?

1 Answers1

1

The user code needs to explicitly tell the compiler its own function (the one you did not show) to be __stdcall, if that is what the DLL expects. Something like

__stdcall myCTMCashAccept (
   const struct CTMEventInfo,
   const struct CTMAcceptEvent)
{
  //...
}
// ...
  ctm_add_cash_accept_event_handler(myCTMCashAccept);

should work.

Remember that the #define LIBCTMCLIENT_FUNC you showed is about the convention for user code calling the DLL; while the callback, with its typedef, is about the other way: it is the DLL calling the user code. They do not have to use the same conventions (although it is clearer when they do); so if your user code is likely to use __cdecl code (perhaps because it already exists), then you should remove the __stdcall from the typedef (and it should work, too).

AntoineL
  • 888
  • 4
  • 25
  • I don't think CTMCashAcceptCallback has other code details because it is a callback signature (function pointer). – aljochimera Mar 19 '15 at 07:18
  • @aljochimera: I meant the function, provided by some "user" (as opposed to the "library" which is the DLL), which type is compatible with functions pointed to by CTMCashAcceptCallback pointers. Sorry for the confusion between callbacks (functions), and CTMCashAcceptCallback objects, which are pointers to functions. – AntoineL Mar 19 '15 at 20:34
  • thanks @AntoineL! you're right after adding stdcall to the function the message is no longer displayed. – aljochimera Mar 20 '15 at 08:54