为什么微软选择 stdcall 作为他们的 API 约定? [英] Why did Microsoft choose stdcall as their API convention?

查看:27
本文介绍了为什么微软选择 stdcall 作为他们的 API 约定?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有充分的理由吗?

它们的内部函数(未导出)是否也是 stdcall 约定?

Are their internal functions (not exported) also stdcall convention?

推荐答案

这是对 32 位代码的 pascal 调用约定的改编.Pascal 是 OS/2 和 Windows 3 等 16 位操作系统的调用约定.为什么选择 pascal 有点猜测,即使我当时还是个小崽子,但它的效率要高一些.当您只需要处理 640 KB 时,这很重要.

It was an adaptation to the pascal calling convention for 32-bit code. Pascal was the calling convention for 16-bit operating systems like OS/2 and Windows 3. Why pascal was chosen is a bit of a guess, even I was a small pup back then, but it is slightly more efficient. Which mattered back when 640 KB was all you had to work with.

大多数 Win32 函数都不是真正的 stdcall,因为它还规定了在呈现给链接器之前如何修饰导出的函数.就像 void Mumble(int arg) 变成了 _Mumble@4.@ 后面的数字描述了激活帧的大小.但是大多数 Win32 函数都是在没有任何修饰的情况下导出的.可能是为了给程序员一个让 GetProcAddress() 工作的机会.我认为装饰是为了帮助链接器检测声明的 API 函数签名和实际签名之间的不匹配.传递的参数数量不匹配是一种自动kaboom,因为被调用者将从堆栈中弹出更多或更少的参数,然后传递.也很难诊断.stdcall 的一个弱点,cdecl 约定没有这个问题.

Most Win32 functions aren't true stdcall as it also prescribes how the exported function is decorated before presented to the linker. Like void Mumble(int arg) becomes _Mumble@4. The number after the @ describes the activation frame size. But most Win32 functions are exported without any decoration. Probably to give the programmer a fighting chance to make GetProcAddress() work. I think the decoration was intended to help the linker detect mismatches between the declared API function signature and the actual one. Having a mismatch in the number of passed arguments is an automatic kaboom since the callee will pop more or less arguments off the stack then were passed. Hard to diagnose too. A weakness of stdcall, the cdecl convention doesn't have this problem.

内部调用是 stdcall、cdecl 和 thiscall 之间的混合包.不能说我曾经检测到一种模式,尽管单步执行 Windows 代码不是我喜欢做的事情.

Internal calling is a mixed bag between stdcall, cdecl and thiscall. Can't say I've ever detected a pattern, although single-stepping Windows code isn't something I enjoy doing.

这篇关于为什么微软选择 stdcall 作为他们的 API 约定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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