Skip to content

Instantly share code, notes, and snippets.

@chowey
Last active August 29, 2015 14:00
Show Gist options
  • Save chowey/fe52a1616a45bebbdcc0 to your computer and use it in GitHub Desktop.
Save chowey/fe52a1616a45bebbdcc0 to your computer and use it in GitHub Desktop.
C++ Win32 AlertIfError
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