Nasm - 不弹出参数的 Winapi 函数

Nasm - Winapi functions that do not pop their parameters

我在 Nasm 中编写了一个程序,我发现虽然像 CreateProcessAGetModuleFileNameA 这样的 winapi 函数在完成后确实会从堆栈中弹出它们的参数,printf 没有那样做。

这有什么原因吗?更重要的是:是否有任何其他 winapi 函数不从堆栈中弹出元素?因为我的程序运行不正常,我想确定它的 none 是由未弹出的值引起的。

99% 的导出 Windows 函数使用 stdcall calling convention。在 32 位 x86 上,这会创建更小、更高效的代码,因为被调用方会恢复堆栈。

参数数量可变的函数不能使用 stdcall,因为只有调用者知道有多少参数,因此调用者必须恢复堆栈。

printf不是Windows函数,它是一个C库函数,大多数C库使用cdecl calling convention where the caller restores the stack. The Windows provided print functions like wsprintf也是cdecl。您可以假设任何以 ... 结尾的 API 函数作为最终参数使用 cdecl.