How to translate NTSTATUS error codes to message strings (259693)



The information in this article applies to:

  • Microsoft Windows 2000 Driver Development Kit (DDK)
  • Microsoft Windows NT 4.0 Driver Development Kit (DDK)
  • Microsoft Windows Server 2003 Driver Development Kit (DDK)
  • Microsoft Windows XP Driver Development Kit (DDK)

This article was previously published under Q259693

SUMMARY

Most Kernel Mode API functions return NTSTATUS values. To translate these status values to messages by using the FormatMessage API function, you must reference the NtDLL.dll module in the parameter list.

MORE INFORMATION

The following code sample demonstrates how to obtain the system message string.
void DisplayError(DWORD NTStatusMessage)
{
   LPVOID lpMessageBuffer;
   HMODULE Hand = LoadLibrary("NTDLL.DLL");
   
   FormatMessage( 
       FORMAT_MESSAGE_ALLOCATE_BUFFER | 
       FORMAT_MESSAGE_FROM_SYSTEM | 
       FORMAT_MESSAGE_FROM_HMODULE,
       Hand, 
       Err,  
       MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
       (LPTSTR) &lpMessageBuffer,  
       0,  
       NULL );

   // Now display the string.

   // Free the buffer allocated by the system.
   LocalFree( lpMessageBuffer ); 
   FreeLibrary(Hand);
}
				
NTSTATUS values are defined in the Ntstatus.h header file that is included in the Windows NT and Windows 2000 DDK.

Modification Type:MajorLast Reviewed:6/29/2005
Keywords:kbhowto KB259693 kbAudDeveloper