What does the CALLBACK keyword mean in a Win-32 C ++ application?

Some function calls in Win-32 C ++ applications have an applicable CALLBACK keyword, as in this example (taken from this MSDN page ):

 BOOL CALLBACK DeleteItemProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam) { // ... code here ... } 

I see through Visual Studio that the CALLBACK keyword is defined (using #define ) as __stdcall . The __ stdcall documentation does not make it clearer (at least for me) what it does.

In short, what does CALLBACK for me ? Is this absolutely necessary, or can I leave this declaration?

+4
source share
3 answers

Required, __stdcall is not a standard call for most compilers. __cdecl is the standard default value. Incorrect call access will make your program bad in a quandary. The argument values ​​are incorrect and the stack becomes unbalanced.

This is only a problem in 32-bit code, 64-bit code has only one calling convention. Whoever adds another, he will be temporarily banned from a small island in the South Atlantic for life. __stdcall is a historical accident that began with the agreement on calling pascal in DOS and 16-bit Windows, back when shaving commands from a call was important when small memory was available.

+12
source

CALLBACK defined as the __stdcall mechanism. But this is a function in itself, which will be called by some other function when an event occurs (say).

It is necessary? Yes! What for? because by default __cdecl

+1
source

CALLBACK not a keyword. This is just a preprocessor macro, which is replaced by the corresponding calling convention, which, as you already noted, is __stdcall .

This conditional convention, called "Pascal-like", which does not support a variable number of arguments , was used by the Win32 API from the earliest days, and still exists for historical reasons.

+1
source

All Articles