Reputation: 271
I've been trying to get the Hardware GUID, and I found this function posted on the web.
#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();
}
The problem is, whenever I try to compile it, I get "error: 'GetCurrentHwProfile' was not declared in this scope". I'm using MinGW's G++. Maybe that's the problem?
Upvotes: 0
Views: 1104
Reputation: 6147
The function GetCurrentHwProfile()
is declared in the winbase.h
header:
WINBASEAPI BOOL WINAPI GetCurrentHwProfileA(LPHW_PROFILE_INFOA);
WINBASEAPI BOOL WINAPI GetCurrentHwProfileW(LPHW_PROFILE_INFOW);
Note that it is either GetCurrentHwProfileA
(for Ansi) or GetCurrentHwProfileW
(for Unicode / wide characters). I can find no sign of a macro which aliases GetCurrentHwProfile
to either of the two functions, depending on a defined UNICODE
.
So, the current solution seems to use either GetCurrentHwProfileA
or GetCurrentHwProfileW
or do something like
#ifdef UNICODE
#define GetCurrentHwProfile GetCurrentHwProfileW
#else
#define GetCurrentHwProfile GetCurrentHwProfileA
#endif
Upvotes: 1
Reputation: 13099
Nice catch! (if you could call it that)
The problem is that normally GetCurrentHwProfile would be a short-cut, if you like. When compiling with UNICODE support it gets changed into GetCurrentHwProfileW. Otherwise, it gets changed to GetCurrentHwProfileA.
The solution? Simply add an A on the end. I.e GetCurrentHwProfileA :)
BB.b.b.ut - remember you have to change it explictly if you decide to use unicode after-all. A much cleaner solution would be to make GetCurrentHwProfile refer to the correct one as needed. I guess it's likely done with something like: (too lazy to look right now. All the windows functions use this trick, guess the minGW crowd missed this little gem that is GetCurrentHwProfile)
#ifdef UNICODE
#define GetCurrentHwProfile GetCurrentHwProfileW
#else
#define GetCurrentHwProfile GetCurrentHwProfileA
#endif
Upvotes: 1