Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #12073 from AdmiralCurtiss/wiimote-win32error
WiimoteReal/IOWin: Use correct error type in the default case.
  • Loading branch information
JosJuice committed Jul 29, 2023
2 parents 163c97e + fb9274c commit 30c4ac3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
8 changes: 7 additions & 1 deletion Source/Core/Common/CommonFuncs.cpp
Expand Up @@ -52,10 +52,16 @@ std::string LastStrerrorString()
// Wrapper function to get GetLastError() string.
// This function might change the error code.
std::string GetLastErrorString()
{
return GetWin32ErrorString(GetLastError());
}

// Like GetLastErrorString() but if you have already queried the error code.
std::string GetWin32ErrorString(DWORD error_code)
{
char error_message[BUFFER_SIZE];

FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, nullptr, GetLastError(),
FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, nullptr, error_code,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), error_message, BUFFER_SIZE, nullptr);
return std::string(error_message);
}
Expand Down
3 changes: 3 additions & 0 deletions Source/Core/Common/CommonFuncs.h
Expand Up @@ -53,6 +53,9 @@ std::string LastStrerrorString();
// This function might change the error code.
std::string GetLastErrorString();

// Like GetLastErrorString() but if you have already queried the error code.
std::string GetWin32ErrorString(unsigned long error_code);

// Obtains a full path to the specified module.
std::optional<std::wstring> GetModuleName(void* hInstance);
#endif
Expand Down
13 changes: 2 additions & 11 deletions Source/Core/Core/HW/WiimoteReal/IOWin.cpp
Expand Up @@ -298,17 +298,8 @@ int IOWritePerWriteFile(HANDLE& dev_handle, OVERLAPPED& hid_overlap_write,
// Pending is no error!
break;
default:
if (FAILED(error))
{
WARN_LOG_FMT(WIIMOTE, "IOWrite[WWM_WRITE_FILE]: Error on WriteFile: {}",
Common::HRWrap(error));
}
else
{
WARN_LOG_FMT(WIIMOTE,
"IOWrite[WWM_WRITE_FILE]: Unexpected error code from WriteFile: 0x{:08x}",
error);
}
WARN_LOG_FMT(WIIMOTE, "IOWrite[WWM_WRITE_FILE]: Error on WriteFile: {}",
Common::GetWin32ErrorString(error));
CancelIo(dev_handle);
return 0;
}
Expand Down

0 comments on commit 30c4ac3

Please sign in to comment.