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

时间:2013-03-21 10:09:00

标签: c++ g++ mingw

我一直在尝试获取硬件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: %s\n",    hwProfileInfo.szHwProfileGuid);
            printf("Hardware Profile: %s\n", hwProfileInfo.szHwProfileName);
    }else{
            return 0;
    }

    getchar();
}

问题是,每当我尝试编译它时,我都会收到“错误:'GetCurrentHwProfile'未在此范围内声明”。我正在使用MinGW的G ++。也许这就是问题?

2 个答案:

答案 0 :(得分:1)

好的抓住! (如果你可以称之为)

问题在于,如果你愿意,通常GetCurrentHwProfile会是一个捷径。使用UNICODE支持进行编译时,它将更改为GetCurrentHwProfileW。否则,它将更改为GetCurrentHwProfileA。

解决方案? 只需在末尾添加A.即GetCurrentHwProfileA :)

BB.b.b.ut - 如果你决定使用unicode,你必须明确地改变它。一个更清洁的解决方案是让GetCurrentHwProfile根据需要引用正确的解决方案。我想这很可能是这样的:(现在懒得看。所有的windows函数都使用这个技巧,猜猜minGW人群错过了这个小宝石,即GetCurrentHwProfile)

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

答案 1 :(得分:1)

函数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
相关问题