WINAPI 代表什么 [英] what does WINAPI stand for

查看:30
本文介绍了WINAPI 代表什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开始学习 C 语言中的 Win32 API.我看到主要功能类似于

I've started to learn Win32 API in C. I saw that the main function is something like

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

但我知道C中的函数就像

but I know that a function in C is like

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

在这种情况下,返回类型是 int 并且函数名称是 WinMain.那么 WINAPI 代表什么,是否有必要?

In this case the return type is int and the function name is WinMain. So what does the WINAPI stand for and is it necessary?

谢谢.:)

推荐答案

它指定了调用约定,这是函数参数在堆栈上的放置和管理方式.

It's specifying the calling convention, which is how arguments to functions are placed and managed on the stack.

您可以混合调用约定,例如,如果您正在调用一些外部代码,例如 Windows API,只要每个人都在同一个页面"上满足他们的期望.

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.

典型的 c 调用是使用所谓的 cdecl 编译的.在 cdecl 中,调用者清除压入堆栈的参数.

Typical c calls are compiled using what's known as cdecl. In cdecl the caller cleans up the arguments pushed on the stack.

WINAPI,也称为标准调用",意思是被调用的函数负责清理它的参数栈.

WINAPI, also known as "standard call" means that the called function is responsible for cleaning up the stack of its arguments.

MS 编译器会在 cdecl 调用前加上 _ 前缀,而 WINAPI 会得到一个前导 _ 并在处理函数名称时在函数名称前加上一个 @{BYTES-NEEDED}.来自上面的链接:

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. From the link above:

call        _sumExample@8  ;WINAPI
call        _someExample   ;cdecl

这篇关于WINAPI 代表什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆