Article ID: 259693 - Last Review: June 29, 2005 - Revision: 3.0

How to translate NTSTATUS error codes to message strings

This article was previously published under Q259693
Expand all | Collapse all

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.

APPLIES TO
  • Microsoft Win32 Device Driver Kit for Windows 2000
  • Microsoft Windows NT 4.0 Driver Development Kit
  • Microsoft Windows Server 2003 Driver Development Kit
  • Microsoft Windows XP Driver Development Kit
Keywords: 
kbhowto KB259693
 

Article Translations