CommonFuncs: Add GetWin32ErrorString().
This commit is contained in:
parent
17fa9dfc4e
commit
cd923718c3
|
@ -52,10 +52,16 @@ std::string LastStrerrorString()
|
||||||
// Wrapper function to get GetLastError() string.
|
// Wrapper function to get GetLastError() string.
|
||||||
// This function might change the error code.
|
// This function might change the error code.
|
||||||
std::string GetLastErrorString()
|
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];
|
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);
|
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), error_message, BUFFER_SIZE, nullptr);
|
||||||
return std::string(error_message);
|
return std::string(error_message);
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,6 +53,9 @@ std::string LastStrerrorString();
|
||||||
// This function might change the error code.
|
// This function might change the error code.
|
||||||
std::string GetLastErrorString();
|
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.
|
// Obtains a full path to the specified module.
|
||||||
std::optional<std::wstring> GetModuleName(void* hInstance);
|
std::optional<std::wstring> GetModuleName(void* hInstance);
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue