Switch to ANSI Windows API in Win32ErrorString() function

This commit is contained in:
Hennadii Stepanov committed 2025-10-06 19:41:35 +01:00
1 parent 06d0be4e22
commit dbe770d921
1 file changed
+5 -10
+5 -10
View File
@@ -12,8 +12,6 @@
#if defined(WIN32) #if defined(WIN32)
#include <windows.h> #include <windows.h>
#include <locale>
#include <codecvt>
#endif #endif
std::string SysErrorString(int err) std::string SysErrorString(int err)
@@ -41,16 +39,13 @@ std::string SysErrorString(int err)
#if defined(WIN32) #if defined(WIN32)
std::string Win32ErrorString(int err) std::string Win32ErrorString(int err)
{ {
wchar_t buf[256]; char buf[256];
buf[0] = 0; buf[0] = 0;
if(FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_MAX_WIDTH_MASK, if (FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_MAX_WIDTH_MASK,
nullptr, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), nullptr, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
buf, ARRAYSIZE(buf), nullptr)) buf, ARRAYSIZE(buf), nullptr)) {
{ return strprintf("%s (%d)", buf, err);
return strprintf("%s (%d)", std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>,wchar_t>().to_bytes(buf), err); } else {
}
else
{
return strprintf("Unknown error (%d)", err); return strprintf("Unknown error (%d)", err);
} }
} }