Fix #11948: [Win32] Convert error messages to utf8 (#11951)

This commit is contained in:
Loïc Guilloux
2024-02-02 16:30:23 +01:00
committed by GitHub
parent 3545decf2d
commit 0e738dda88
3 changed files with 13 additions and 12 deletions

View File

@@ -73,15 +73,16 @@ NetworkHTTPRequest::NetworkHTTPRequest(const std::wstring &uri, HTTPCallback *ca
static std::string GetLastErrorAsString()
{
char buffer[512];
wchar_t buffer[512];
DWORD error_code = GetLastError();
if (FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_FROM_HMODULE | FORMAT_MESSAGE_IGNORE_INSERTS, GetModuleHandleA("winhttp.dll"), error_code,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buffer, sizeof(buffer), nullptr) == 0) {
if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_FROM_HMODULE | FORMAT_MESSAGE_IGNORE_INSERTS, GetModuleHandle(L"winhttp.dll"), error_code,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buffer, lengthof(buffer), nullptr) == 0) {
return fmt::format("unknown error {}", error_code);
}
return buffer;
return FS2OTTD(buffer);
}
/**