About function call Way __stdcall and __cdecl detailed
__stdcall
__cdecl
The similarities and differences between the two points
Instance
__stdcall
__stdcall's full name is standard call. is the standard invocation method for C + +.
function parameters are in the stack order from right to left. function returns with the RETN x instruction, where x is the number of bytes to adjust the stack. This method is called Automatic clearing stack. That is, the number of parameters of the called function is fixed, the caller must strictly follow the definition of the pass parameters, one is not much, a lot.
__cdecl
__cdecl's full name is C declaration, which is the default function invocation of C language.
function parameters are in the stack order from right to left. function to act as a RET instruction when returning functions. Manually clearing the stack by the caller. The called function supports variable parameters. The caller manually balances the stack based on the number of arguments passed in at the time of the call.
The similarities and differences between the two points
Same point
Parameter stack order is the same: from right to left
Different points
Stack balance mode is different: __stdcall automatic cleaning stack, __cdecl manual cleaning stack.
Return instruction is different: _stdcall uses RETN x, __CDECL uses RET
The decorated name of the compiled function is different: suppose there is a function int foo (int a, int b), with the __stdcall compiled function named _foo@8, and the __cdecl compiled function named _foo.
Instance
Functions that support variable parameters must be defined as __cdecl, such as:
int printf (char *fmt, ...);
Definition of __stdcall and __cdecl in windef.h
#define CALLBACK __stdcall
#define WINAPI __stdcall
#define WINAPIV __cdecl
#define Apientry WINAPI
#define Apiprivate __stdcall
#define PASCAL __stdcall
#define CDECL _ Cdecl
#ifndef cdecl
#define CDECL _cdecl
#endif
The above is a small series for you to bring about the function of the way __stdcall and __cdecl the full content of the detailed, I hope to help you, a lot of support cloud Habitat Community ~