Instantly share code, notes, and snippets.

Embed
What would you like to do?
How to format the output of Win32's GetLastError() method into a string using FormatString
DWORD dLastError = GetLastError();
LPCTSTR strErrorMessage = NULL;
FormatMessage(
FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_ARGUMENT_ARRAY | FORMAT_MESSAGE_ALLOCATE_BUFFER,
NULL,
dLastError,
0,
(LPWSTR) &strErrorMessage,
0,
NULL);
//Prints debug output to the console
OutputDebugString(strErrorMessage);
@nazikus

This comment has been minimized.

nazikus commented May 29, 2014

for consistency, change casting from LPWSTR to LPTSTR at line 9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment