C++函数前加宏表示的意思

在VC编程中,也许大家会遇到如下函数定义:

LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)

相信大家都知道这个函数,但分析似乎比平常的函数定义多了CALLBACK。

 

现在分析如下:

LRESULT为返回值,实际上是LONG

CALLBACK为宏,#define CALLBACK    __stdcall。是定义一种调用约定。

作用是:

Pushes parameters on the stack, in reverse order (right to left)

意思:将参数按反序(从右到左)压入堆栈中。

 

 

其他宏:

calling conventions
The following calling conventions are supported by the Visual C/C++ compiler.

Keyword  Stack cleanup  Parameter passing 
__cdecl
Caller
Pushes parameters on the stack, in reverse order (right to left)

__clrcall
n/a
Load parameters onto CLR expression stack in order (left to right).

__stdcall
Callee
Pushes parameters on the stack, in reverse order (right to left)

__fastcall
Callee
Stored in registers, then pushed on stack

__thiscall
Callee
Pushed on stack; this pointer stored in ECX


Calling convention for callback functions.
This type is declared in WinDef.h as follows:
#define CALLBACK __stdcall

你可能感兴趣的:(C++函数前加宏表示的意思)