比如void WINAPI fun(),这样定义和没有WINAPI有什么区别?

解决方案 »

  1.   

    #define WINAPI __stdcallcalling convention
      

  2.   

    能不能具体解释一下MSDN上这样写:
    The __stdcall calling convention is used to call Win32 API functions. The callee cleans the stack, so the compiler makes vararg functions __cdecl. Functions that use this calling convention require a function prototype.但还是不太明白
      

  3.   

    其实calling convention没什么特别的,就是谁清除堆栈和参数压栈顺序问题(是最后一个参数先压栈,还是第一个参数先压栈)
      

  4.   

    谢谢回复那
    void aaa(int i)

    void WINAPI aaa(int i)
    有什么差别?我看到别人代码里有WINAPI,但不知为何要这样用
      

  5.   

    一般来说对于你普通的函数可有可无,看你个人喜好。WINAPI表示_stdcall,没有的话则默认为_cdecl。
    比如有些地方明确需要你使用WINAPI调用约定,像窗口的回调、线程函数等等,这时候你就必须写明WINAPI。
      

  6.   

    MSDN上找到的:__cdecl 细节
    对于 C,__cdecl 命名约定使用以下划线 ( _ ) 开头的函数名;不执行任何大小写转换。除非声明为 extern "C",否则 C++ 函数将使用不同的名称修饰方案。__stdcall 细节
    __stdcall 函数的参数被从右到左推送到堆栈上,被调用函数在返回之前从堆栈中弹出这些参数。