Last active
August 29, 2015 14:00
-
-
Save chowey/fe52a1616a45bebbdcc0 to your computer and use it in GitHub Desktop.
C++ Win32 AlertIfError
This file contains hidden or 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
void AlertIfError() { | |
DWORD dw = GetLastError(); | |
if (dw == ERROR_SUCCESS) { | |
return; | |
} | |
LPTSTR lpMsgBuf; | |
FormatMessage( | |
FORMAT_MESSAGE_ALLOCATE_BUFFER | | |
FORMAT_MESSAGE_FROM_SYSTEM | | |
FORMAT_MESSAGE_IGNORE_INSERTS, | |
NULL, | |
dw, | |
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), | |
(LPTSTR) &lpMsgBuf, // weird? | |
0, | |
NULL); | |
MessageBox(GetForegroundWindow(), lpMsgBuf, L"Error", MB_OK); | |
LocalFree(lpMsgBuf); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment