Skip to content

Instantly share code, notes, and snippets.

@Neferetheka
Created August 22, 2012 09:27
Show Gist options
  • Save Neferetheka/3424009 to your computer and use it in GitHub Desktop.
Save Neferetheka/3424009 to your computer and use it in GitHub Desktop.
Display last C++ error in Visual Studio output console
DWORD dw = GetLastError();
char *TextSize;
std::printf("Error has occured: ");
FormatMessage(0x00000100 | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, 0,
dw, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) &TextSize, 0, 0);
OutputDebugString((LPCWSTR)TextSize);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment