How to translate NTSTATUS error codes to message strings

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.
Eigenschaften

Artikelnummer: 259693 – Letzte Überarbeitung: 29.06.2005 – Revision: 1

Feedback