DWORD error;
error = GetLastError();
printf("GetLastError is : %d/n",error);
LPVOID buffer;
::FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
error,
0,
(LPTSTR)&buffer,
0,
NULL );
printf("The Error is : %s /n", buffer);
MSDN:
You should call the GetLastError function immediately when a function's return value indicates that such a call will return useful data. That is because some functions call SetLastError with a zero when they succeed, wiping out the error code set by the most recently failed function.