WINAPI宏与CALLBACK宏有什么用?又有什么区别?

dkbrain 2009-10-14 10:56:16
#define CALLBACK    __stdcall
#define WINAPI __stdcall
#define WINAPIV __cdecl
#define APIENTRY WINAPI
#define APIPRIVATE __stdcall
#define PASCAL __stdcall

上面是这些宏的定义,但是不是很明白这些宏到底有什么用。
只是模模糊糊的知道这些关系到动态库的调用协议;有哪位牛人详细系统的讲下这方面的知识。

...全文
592 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
fish_gao 2009-10-14
  • 打赏
  • 举报
回复
没有区别,有些见人时候说自己是人,见鬼时候说自己是鬼的意味
飞天赤狐 2009-10-14
  • 打赏
  • 举报
回复
补充,他们的实质是不一样的,
当然都是_stdcall的宏当然是一样了
但是 _stdcall和_cdecl是有区别的

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


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

你可以用两种方式分别定义一个函数,然后用反汇编视图进行调试,看看代码的区别
主要体现在push 参数和函数执行完成后恢复栈上
飞天赤狐 2009-10-14
  • 打赏
  • 举报
回复
这些都是函数的标准,即编译器在编译函数时入栈和出栈的不同标准
参照MSDN:


Microsoft Specific

All arguments are widened to 32 bits when they are passed. Return values are also widened to 32 bits and returned in the EAX register, except for 8-byte structures, which are returned in the EDX:EAX register pair. Larger structures are returned in the EAX register as pointers to hidden return structures. Parameters are pushed onto the stack from right to left. Structures that are not PODs will not be returned in registers.

The compiler generates prolog and epilog code to save and restore the ESI, EDI, EBX, and EBP registers, if they are used in the function.

Note
When a struct, union, or class is returned from a function by value, all definitions of the type need to be the same, else the program may fail at runtime.


For information on how to define your own function prolog and epilog code, see Naked Function Calls.

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


For related information, see Obsolete Calling Conventions.

END Specific

See Also
Reference
Calling Conventions


To make a suggestion or report a bug about Help or another feature of this product, go to the feedback site.
jenglev 2009-10-14
  • 打赏
  • 举报
回复
实质一样,为了更好理解而已
dong364 2009-10-14
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 xylicon 的回复:]
_stdcall是pascal程序的缺省调用方式,通常用于win32 api中,函数采用从右到左的压栈方式,自己在退出时清空堆栈。vc将函数编译后会在函数名前面加上下划线前缀,在函数名后加上"@"和参数的字节数。

_cdecl是c和c++程序的缺省调用方式。每一个调用它的函数都包含清空堆栈的代码,所以产生的可执行文件大小会比调用_stdcall函数的大。函 数采用从右到左的压栈方式。vc将函数编译后会在函数名前面加上下划线前缀。是mfc缺省调用约定。

[/Quote]
PS:_cdecl是C的调用约定和C++全局函数(不属于类的函数)的调用约定,还有_stdcall函数编译后产生的修饰名也不像上述说的简单
yayafu 2009-10-14
  • 打赏
  • 举报
回复
没区别,只是将就习惯和看上去表示不同意义
jasonM2008 2009-10-14
  • 打赏
  • 举报
回复
宏,就是一个替代的东东,实际上编译的时候宏就被替换了!
oyljerry 2009-10-14
  • 打赏
  • 举报
回复
标准Windows函数调用约定,一般对于回调函数,标准Windows DLL导出函数等都用这个函数调用约定...
neohope 2009-10-14
  • 打赏
  • 举报
回复
是一样的,但是函数的用途是不一样的,就是提醒你,函数究竟是回调函数还是别的什么
MoXiaoRab 2009-10-14
  • 打赏
  • 举报
回复
typedef HANDLE HWND;
typedef HANDLE HPEN;
typedef HANDLE HMENU;

我问你,HPEN和HMENU有区别吗?
xylicon 2009-10-14
  • 打赏
  • 举报
回复
_stdcall是pascal程序的缺省调用方式,通常用于win32 api中,函数采用从右到左的压栈方式,自己在退出时清空堆栈。vc将函数编译后会在函数名前面加上下划线前缀,在函数名后加上"@"和参数的字节数。

_cdecl是c和c++程序的缺省调用方式。每一个调用它的函数都包含清空堆栈的代码,所以产生的可执行文件大小会比调用_stdcall函数的大。函 数采用从右到左的压栈方式。vc将函数编译后会在函数名前面加上下划线前缀。是mfc缺省调用约定。
百事烟 2009-10-14
  • 打赏
  • 举报
回复
一样,没啥区别
A1erX 2009-10-14
  • 打赏
  • 举报
回复
http://blog.vckbase.com/arong/archive/2004/06/09/409.html
delphiwcdj 2009-10-14
  • 打赏
  • 举报
回复
如果定义的约定和使用的约定不一致,则将导致堆栈被破坏。
幸福官 2009-10-14
  • 打赏
  • 举报
回复
没有实际上的区别,就是一个约定
jingzhongrong 2009-10-14
  • 打赏
  • 举报
回复
方便理解用的。

16,470

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧