Microsoft KB Archive/259693

{|
 * width="100%"|

HOWTO: Translate NTSTATUS Error Codes to Message Strings

 * }

Q259693

-

The information in this article applies to:


 * Microsoft Windows 2000 Driver Development Kit (DDK)
 * Microsoft Windows NT 4.0 Driver Development Kit (DDK)

-

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

MORE INFORMATION
The following code sample demonstrates how to get the system message string.

void DisplayError(DWORD NTStatusMessage) {  LPVOID lpMessageBuffer; HMODULE Hand = LoadLibrary(&quot;NTDLL.DLL&quot;); 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 header file Ntstatus.h included in the Windows NT and Windows 2000 DDK.