Skip to content

Commit

Permalink
deviceinfo: Fix character encoding for GetComputerName.
Browse files Browse the repository at this point in the history
Should be UTF8.

Fixes: #651
  • Loading branch information
ben-clayton committed Jun 29, 2017
1 parent 6b61454 commit c17238c
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions core/os/device/deviceinfo/cc/windows/query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ struct Context {
HDC mHDC;
HGLRC mCtx;
int mNumCores;
char mHostName[MAX_COMPUTERNAME_LENGTH+1];
char mHostName[MAX_COMPUTERNAME_LENGTH*4+1]; // Stored as UTF-8
OSVERSIONINFOEX mOsVersion;
const char* mOsName;
};
Expand Down Expand Up @@ -146,7 +146,21 @@ bool createContext(void* platform_data) {
gContext.mNumCores = sysInfo.dwNumberOfProcessors;

DWORD size = MAX_COMPUTERNAME_LENGTH + 1;
GetComputerNameA(gContext.mHostName, &size);
WCHAR host_wide[MAX_COMPUTERNAME_LENGTH + 1];
if (!GetComputerNameW(host_wide, &size)) {
snprintf(gContext.mError, sizeof(gContext.mError),
"Couldn't get host name: %d", GetLastError());
}
WideCharToMultiByte(
CP_UTF8, // CodePage
0, // dwFlags
host_wide, // lpWideCharStr
-1, // cchWideChar
gContext.mHostName, // lpMultiByteStr
sizeof(gContext.mHostName), // cbMultiByte
nullptr, // lpDefaultChar
nullptr // lpUsedDefaultChar
);

return true;
}
Expand Down

0 comments on commit c17238c

Please sign in to comment.