简体   繁体   English

WINAPI代表什么?

[英]what does WINAPI stand for

I've started to learn Win32 API in C. I saw that the main function is something like 我已经开始在C中学习Win32 API。我看到主要功能是类似的

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow) { .. }

but I know that a function in C is like 但我知道C中的函数就像

[ReturnType] [FunctionName] (Args) { .. }

In this case the return type is int and the function name is WinMain. 在这种情况下,返回类型为int,函数名称为WinMain。 So what does the WINAPI stand for and is it necessary? 那么WINAPI代表什么,是否有必要?

Thank you . 谢谢 。 :) :)

It's specifying the calling convention , which is how arguments to functions are placed and managed on the stack. 它指定了调用约定 ,即函数的参数在堆栈上的放置和管理方式。

You can mix calling conventions, say if you're calling some external code, like windows APIs, as long as everyone is on the same "page" with their expectations. 您可以混合使用调用约定,例如,如果您正在调用某些外部代码,例如Windows API,只要每个人都在他们期望的同一“页面”上。

Typical c calls are compiled using what's known as cdecl. 典型的c调用使用所谓的cdecl编译。 In cdecl the caller cleans up the arguments pushed on the stack. 在cdecl中,调用者清理堆栈上推送的参数。

WINAPI, also known as "standard call" means that the called function is responsible for cleaning up the stack of its arguments. WINAPI,也称为“标准调用”,意味着被调用函数负责清理其参数堆栈。

The MS compiler will prefix a cdecl call with a _, while a WINAPI gets a leading _ and gets an @{BYTES-NEEDED} prepended to the function name when it mangles the function names. MS编译器将使用_前缀cdecl调用,而WINAPI获取前导_并在函数名称变形时获得函数名称前面的@ {BYTES-NEEDED}。 From the link above: 从上面的链接:

call        _sumExample@8  ;WINAPI
call        _someExample   ;cdecl

It is "calling convention", defined as macro with #define and resolves to __stdcall . 它是“调用约定”,用#define定义为宏并解析为__stdcall

Read more on MSDN : 在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. DLL使用的Windows标准进程间调用约定称为WinAPI约定。 It is defined in Windows header files as WINAPI, which is in turn defined using the Win32 declarator __stdcall. 它在Windows头文件中定义为WINAPI,后者又使用Win32声明符__stdcall定义。

Win - Windows 赢 - Windows

API - Application Programming Interface API - 应用程序编程接口

Windows Application Programming Interface Windows应用程序编程接口

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM