Some function calls in Win-32 C++ applications have the CALLBACK
keyword applied to them, as in this example (taken from this MSDN page):
BOOL CALLBACK DeleteItemProc(HWND hwndDlg, UINT message,
WPARAM wParam, LPARAM lParam)
{
// ... code here ...
}
I see via Visual Studio that the CALLBACK
keyword is defined (using #define
) as __stdcall
. The __stdcall documentation doesn't make it much clearer (to me at least) what it does.
In short, what does using CALLBACK
do for me? Is it absolutely required, or can I leave that declaration off?
It is required, __stdcall is not the default calling convention on most compilers. __cdecl is the normal default. Having the calling convention wrong will make your program misbehave in a hard to diagnose way. The argument values are wrong and the stack gets imbalanced.
It is only an issue in 32-bit code, 64-bit code has only one calling convention. Whomever adds another one is going to be summarily banned to a small island in the South Atlantic for life. __stdcall is an historic accident that started with the pascal calling convention in DOS and 16-bit Windows, back when shaving an instruction off the call was important when so little memory was available.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With