Visual Studio Notes Errors
Visual Studio Notes Errors
MS First 500 Error numbers.[1]
Uses FormatMessage[2]
MS All Error Messages[3]
SystemErrorMessageToCString formats the error message and returns it as a CString.
CString SystemErrorMessageToCString(DWORD dwErr) { CString result_cs; WCHAR wszMsgBuff[512]; // Buffer for text. DWORD dwChars = 0; // Number of chars returned. // Try to get the message from the system errors. dwChars = FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, dwErr, 0, wszMsgBuff, 512, NULL ); // Display the error message, or generic text if not found. result_cs.Format( _T("Error value: %d Message: %ws"), dwErr, wszMsgBuff); return result_cs; } printf( " last error is: %S ", SystemErrorMessageToCString( 0 ) ); printf( " last error is: %S ", SystemErrorMessageToCString( 1 ) ); printf( " last error is: %S ", SystemErrorMessageToCString( 2 ) ); printf( " last error is: %S ", SystemErrorMessageToCString( 3 ) ); printf( " last error is: %S ", SystemErrorMessageToCString( 4 ) ); Output: last error is: Error value: 0 Message: The operation completed successfully. last error is: Error value: 1 Message: Incorrect function. last error is: Error value: 2 Message: The system cannot find the file specified. last error is: Error value: 3 Message: The system cannot find the path specified. last error is: Error value: 4 Message: The system cannot open the file.
Internal Links
Parent Article: Visual Studio Notes