C++ 主函数中的“WINAPI”是什么意思?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2348442/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What does "WINAPI" in main function mean?
提问by Pyjong
Could you please explain to me the WINAPI
word in the WinMain()
function?
你能向我解释一下函数中的WINAPI
单词WinMain()
吗?
In the simplest way..
以最简单的方式..
#include <windows.h>
int -->WINAPI<-- WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
MessageBox(NULL, "Goodbye, cruel world!", "Note", MB_OK);
return 0;
}
Is it just some Windows funky mode?
它只是一些 Windows 时髦模式吗?
What does it do? Or rather what is this C++ feature I haven't encountered yet?
它有什么作用?或者更确切地说,我还没有遇到过的这个 C++ 特性是什么?
回答by bk1e
WINAPI
is a macro that evaluates to __stdcall
, a Microsoft-specific keyword that specifies a calling convention where the callee cleans the stack. The function's caller and callee need to agree on a calling convention to avoid corrupting the stack.
WINAPI
是一个宏,其计算结果为__stdcall
,一个特定于Microsoft 的关键字,用于指定被调用者清理堆栈的调用约定。函数的调用者和被调用者需要就调用约定达成一致以避免破坏堆栈。
回答by Brian R. Bondy
回答by bobbymcr
This is a macro definition intended to denote the Windows calling convention. From MSDN:
这是一个宏定义,用于表示 Windows 调用约定。从MSDN:
The way the name is decorated depends on the language and how the compiler is instructed to make the function available, that is, the calling convention. The standard inter-process calling convention for Windows used by DLLs is known as the WinAPI convention. It is defined in Windows header files as WINAPI, which is in turn defined using the Win32 declarator __stdcall.
名称的修饰方式取决于语言以及如何指示编译器使函数可用,即调用约定。DLL 使用的 Windows 的标准进程间调用约定称为 WinAPI 约定。它在 Windows 头文件中定义为 WINAPI,而后者又使用 Win32 声明符 __stdcall 定义。
回答by Jerry Coffin
It's Windows-specific. It specifies the calling convention. WinMain gets called by Windows, and this ensures that the caller and callee agree on the calling convention.
它是特定于 Windows 的。它指定调用约定。WinMain 被 Windows 调用,这确保调用者和被调用者就调用约定达成一致。