gpt4 book ai didi

c++ - 为什么 MinGW 将 Win API 函数定义为宏?

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:23:56 25 4
gpt4 key购买 nike

我想知道为什么这么多 Win API 函数只定义了它们在 MinGW 中的实际实现。

示例:

MessageBox() 功能如 MSDN documenation 中所述:

int WINAPI MessageBox(
_In_opt_ HWND hWnd,
_In_opt_ LPCTSTR lpText,
_In_opt_ LPCTSTR lpCaption,
_In_ UINT uType
);

下面是 MinGW 的实现(winuser.h):

#define MessageBox MessageBoxA
/* ... */
WINUSERAPI int WINAPI MessageBoxA(HWND,LPCSTR,LPCSTR,UINT);

所以 MessageBox 不是函数,它只是真正函数的定义。

另一个(取自winbase.h:

#define GetVersionEx GetVersionExA
/* ... */
WINBASEAPI BOOL WINAPI GetVersionExA(LPOSVERSIONINFOA);

如您所见,在大多数情况下,函数都是作为宏来实现的。

这样做有什么理由吗?为什么不将它们实现为“真实” 函数(使用他们的真实姓名)?

最佳答案

来自 GetVersionEx documentation :

Unicode and ANSI names: GetVersionExW (Unicode) and GetVersionExA (ANSI)

来自 Conventions for Function Prototypes documentation :

The preprocessor expands the macro into either the Windows code page or Unicode function name. The letter "A" (ANSI) or "W" (Unicode) is added at the end of the generic function name, as appropriate. The header file then provides two specific prototypes, one for Windows code pages and one for Unicode, as shown in the following examples.

在您的情况下,GetVersionEx 将扩展为 GetVersionExA,因为看起来您正在使用 Windows code page .

关于c++ - 为什么 MinGW 将 Win API 函数定义为宏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16991300/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com