什么是__stdcall? [英] What is __stdcall?

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

问题描述

我在学习Win32编程,和的WinMain 原型如下:

I'm learning about Win32 programming, and the WinMain prototype looks like:

int WINAPI WinMain ( HINSTANCE instance, HINSTANCE prev_instance, PSTR cmd_line, int cmd_show )

我困惑,这是什么 WINAPI 标识符是发现:

#define WINAPI      __stdcall

这是什么呢?我这个有得混淆的返回类型后,在所有。什么是 __ STDCALL 的呢?当有返回类型和函数名之间的事情是什么意思?

What does this do? I'm confused by this having something at all after a return type. What is __stdcall for? What does it mean when there is something between the return type and function name?

推荐答案

__ STDCALL是用于函数调用约定。这告诉编译器,申请设立栈,推参数和得到一个返回值的规则。

__stdcall is the calling convention used for the function. This tells the compiler the rules that apply for setting up the stack, pushing arguments and getting a return value.

有一些其他的调用约定,__cdecl,__thiscall,__fastcall和奇妙命名__naked。 __stdcall是为Win32系统调用标准调用约定。

There are a number of other calling conventions, __cdecl, __thiscall, __fastcall and the wonderfully named __naked. __stdcall is the standard calling convention for Win32 system calls.

维基百科涵盖详细信息

它主要的问题,当你在呼唤你的code之外的功能(例如操作系统API)或操作系统叫你(这里用的WinMain是这样)。如果编译器不知道正确的调用约定,那么你可能会得到非常奇怪的崩溃为堆栈将无法正确管理。

It primarily matters when you are calling a function outside of your code (e.g. an OS API) or the OS is calling you (as is the case here with WinMain). If the compiler doesn't know the correct calling convention then you will likely get very strange crashes as the stack will not be managed correctly.

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

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