WINAPI和CALLBACK

int
WINAPI
WinMain(
 HINSTANCE hInstance,
 HINSTANCE hPrevInstance,
 LPSTR lpCmdLine,
 int nShowCmd
  );
《windows 程序设计》对WINAPI的解释为:
WINAPI识别字在WINDEF.H定义,语句如下:

#define WINAPI __stdcall
该语句指定了一个呼叫约定,包括如何生产机械码以在堆叠中放置函式呼叫的参数。许多Windows函式呼叫宣告为WINAPI。

由被调用的函数清理堆栈,所以参数自左向右入栈,生成的代码中函数名有一个_(下划线)做前缀,一个@和参数总的字节数(十进制)做后缀。它不支持可变参数,但它产生的代码比C的调用协定_cdecl短,因为没有每次调用后的清理堆栈的代码。

下面是MSDN上关于CALLBACK所做的说明:

The [callback] function is useful when the server must obtain information from the client. If server applications were supported on Windows 3.x, the server could make a call to a remote procedure on the Windows 3.x server to obtain the needed information. The callback function accomplishes the same purpose and lets the server query the client for information in the context of the original call.

Callbacks are special cases of remote calls that execute as part of a single thread. A callback is issued in the context of a remote call. Any remote procedure defined as part of the same interface as the static callback function can call the callback function.

The RpcCancelThread function cannot be used to cancel a call that may dispatch a static callback. If a particular remote procedure call will never result in a callback, then it can be canceled. Otherwise, a call can be canceled only if it can be guaranteed that a callback for it has not been issued.

Only the connection-oriented and local-protocol sequences support the callback attribute. The size of the [out] data for callbacks over the local-protocol sequence is limited to 150 bytes. If an RPC interface uses a connectionless (datagram) protocol sequence, calls to procedures with the callback attribute will fail.

Handles cannot be used as parameters in callback functions. Because callbacks always execute in the context of a call, the binding handle used by the client to make the call to the server is also used as the binding handle from the server to the client.

Callbacks can nest to any depth.

阅读更多
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭