GetCurrentHwProfile 未使用 MinGW 的 g++ 编译器在此范围内声明

GetCurrentHwProfile was not declared in this scope using MinGW's g++ compiler

本文关键字:范围内 声明 编译器 g++ 未使用 MinGW GetCurrentHwProfile      更新时间:2023-10-16

我一直在试图获得硬件GUID,我发现这个函数张贴在网上。

#define _WIN32_WINNT 0x0400
#include <windows.h>
#include <stdio.h>
#include <tchar.h>
int main()
{
    HW_PROFILE_INFO hwProfileInfo;
    if(GetCurrentHwProfile(&hwProfileInfo) != NULL){
            printf("Hardware GUID: %sn",    hwProfileInfo.szHwProfileGuid);
            printf("Hardware Profile: %sn", hwProfileInfo.szHwProfileName);
    }else{
            return 0;
    }
    getchar();
}

问题是,每当我试图编译它,我得到"错误:'GetCurrentHwProfile'未在此范围内声明"。我用的是MinGW的g++。也许这就是问题所在?

接得好!(如果你能这么叫的话)

问题是通常GetCurrentHwProfile将是一个快捷方式,如果你喜欢。当使用UNICODE支持编译时,它被更改为GetCurrentHwProfileW。否则,它将被更改为GetCurrentHwProfileA。

解决方案吗?只要在末尾加个A就行了。即GetCurrentHwProfileA:)

BB.b.b。但是-记住,如果您最终决定使用unicode,则必须显式地更改它。更简洁的解决方案是让GetCurrentHwProfile根据需要引用正确的文件。我猜它可能是这样做的:(现在懒得看。所有的窗口函数都使用这个技巧,我猜minGW的人错过了这个小宝石,那就是GetCurrentHwProfile)

#ifdef UNICODE
 #define GetCurrentHwProfile GetCurrentHwProfileW
#else
 #define GetCurrentHwProfile GetCurrentHwProfileA
#endif

函数GetCurrentHwProfile()winbase.h头中声明:

WINBASEAPI BOOL WINAPI GetCurrentHwProfileA(LPHW_PROFILE_INFOA);
WINBASEAPI BOOL WINAPI GetCurrentHwProfileW(LPHW_PROFILE_INFOW);

注意,它是GetCurrentHwProfileA (Ansi)或GetCurrentHwProfileW (Unicode/宽字符)。我找不到将GetCurrentHwProfile别名为两个函数中的任何一个的宏的迹象,这取决于定义的UNICODE

所以,目前的解决方案似乎是使用GetCurrentHwProfileAGetCurrentHwProfileW,或者像
#ifdef UNICODE
#define GetCurrentHwProfile GetCurrentHwProfileW
#else
#define GetCurrentHwProfile GetCurrentHwProfileA
#endif