Created
May 5, 2022 09:54
-
-
Save crsib/cb2785355f145e5e2dbd13e312c19b41 to your computer and use it in GitHub Desktop.
Last system error message
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
std::string GetSysErrorMessage(unsigned long errorCode) | |
{ | |
// get error message from system | |
LPTSTR messageBuffer; | |
if ( | |
::FormatMessage( | |
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | | |
FORMAT_MESSAGE_IGNORE_INSERTS, | |
NULL, errorCode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), | |
(LPTSTR)&messageBuffer, 0, NULL) == 0) | |
{ | |
return {}; | |
} | |
if (messageBuffer == nullptr) | |
return {}; | |
std::string result = messageBuffer; | |
LocalFree(messageBuffer); | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment