+ Reply to Thread
Results 1 to 2 of 2

Thread: What is FormatMessage? How to use it?

  1. #1

    What is FormatMessage? How to use it?

    What is FormatMessage? How to use it?

  2. #2
    Sometimes it may happen that you will need to get the error message text corresponding to the last error code returned by GetLastError() API.

    In that case, FormatMessage can be useful.

    Following is the example:

    CString GetExtendedErrorMessage(DWORD dwLastError)
        LPVOID lpvBuffer ;
    					NULL, dwLastError, 
    					(LPTSTR)&lpvBuffer, 0, NULL) ;
        CString strExtendedError = (LPTSTR) lpvBuffer ;
        // Free the buffer allocated by the system
        LocalFree(lpvBuffer) ;
    	return strExtendedError ;
    CString strExtendedErrorMessage = GetExtendedErrorMessage(GetLastError()) ;

+ Reply to Thread


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts