Skip to content

Commit

Permalink
Common: Fix encoding handling in GetWin32ErrorString
Browse files Browse the repository at this point in the history
These messages can be localized, so we can't just assume it's all ASCII.
  • Loading branch information
JosJuice committed Dec 29, 2023
1 parent b1438c2 commit 8e87b56
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions Source/Core/Common/CommonFuncs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@

#ifdef _WIN32
#include <windows.h>

#define strerror_r(err, buf, len) strerror_s(buf, len, err)

#include "Common/StringUtil.h"
#endif

namespace Common
Expand Down Expand Up @@ -59,11 +62,11 @@ std::string GetLastErrorString()
// Like GetLastErrorString() but if you have already queried the error code.
std::string GetWin32ErrorString(DWORD error_code)
{
char error_message[BUFFER_SIZE];
TCHAR error_message[BUFFER_SIZE];

FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, nullptr, error_code,
FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM, nullptr, error_code,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), error_message, BUFFER_SIZE, nullptr);
return std::string(error_message);
return WStringToUTF8(error_message);
}

// Obtains a full path to the specified module.
Expand Down

0 comments on commit 8e87b56

Please sign in to comment.