Click here to Skip to main content
Licence 
First Posted 23 Mar 2004
Views 34,194
Bookmarked 12 times

An NTSTATUS lookup application

By | 23 Mar 2004 | Article
At times, we need to query NTSTATUS code lookup through FormatMessage function, this is not so handy. So I decided to write a NTSTATUS error code lookup application.

Sample Image - NtStatus.gif

Introduction

Developers usually use Error Lookup Application provided along with the Visual Studio to convert the GetLastError() to user-friendly error strings with detailed description. Well, at times, we also need to query NTSTATUS code lookup through FormatMessage function, this is not so handy. So I decided to write a NTSTATUS error code lookup application.

Background

This is very simple in the sense that just change the Messagesource in FormatMessage function to the handle of NTDLL.DLL.

//
 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM|
  FORMAT_MESSAGE_FROM_HMODULE,Hand,ntStatusMsg,
  MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT),
  (LPTSTR)&lpMessageBuffer,0,NULL);

//

Detailed Explanation

“The FormatMessage function formats a message string. The function requires a message definition as input. The message definition can come from a buffer passed into the function. It can come from a message table resource in an already-loaded module. Or the caller can ask the function to search the system's message table resource(s) for the message definition. The function finds the message definition in a message table resource based on a message identifier and a language identifier. The function copies the formatted message text to an output buffer, processing any embedded insert sequences if requested.” The syntax of FormatMessage is:

//
 DWORD FormatMessage(DWORD dwFlags,LPCVOID lpSource,
   DWORD dwMessageID,DWORD dwLanguageID,LPTSTR lpBuffer, 
   DWORD nSize,va_list* Arguments);
//

The first parameter dwFlags contains the formatting options which are important to us. The full application is included along with. The whole trick is get the handle to the Error Code resource by LoadLibrary.

//
HMODULE Hand = LoadLibrary("NTDLL.DLL");
//

Then simply format the message and pass the ntStatus code to get the corresponding string. Simple !! Isn’t it? But an application would come very handy as error lookup.

//
 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | 
   FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_FROM_HMODULE, 
   Hand,ntStatusMsg,MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT),
   (LPTSTR)&lpMessageBuffer,0,NULL);

//

That's it! So simple. I have made a sample application. You are free to do whatever you want to do with that.

Future Releases

  • To make it as a Visual Studio add-in.
  • To port it to Visual Studio .NET 2003 and make it as add-in for that also.

That's it !!

I know it is too simple, but I found it an interesting way to make a small application that I need for myself and share with my fellow developers.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Tarundeep Singh Kalra

Web Developer

United States United States

Member

Tarun started programming with BASIC,FORTRAN while in school and then gradually became intrested in c,c++ He is now a professional programmer. He is mechanical engineer by qualifications but loves to code and work on latest technologies.
He has worked on various technologies and platforms - Wi-Fi, ISA Servers,Sendmail,VOIP,NDIS Drivers,VLANs etc.He likes to help and mentor people.So if you need any sort of technical help just mail him.
 
visit him at : www.tarunsadhana.com

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralAnother alternative: Error Lookup enhanced PinmemberAntti Keskinen3:02 14 Feb '07  
GeneralAlternative: ntstatus.h Pinmemberzyklopen5:02 18 Jan '07  
GeneralTools | Error Lookup PinmemberRavi Bhavnani4:06 24 Mar '04  
GeneralRe: Tools | Error Lookup PinmemberToby Opferman6:38 24 Mar '04  
GeneralRe: Tools | Error Lookup PinmemberTarundeep Singh Kalra17:19 24 Mar '04  
GeneralRe: Tools | Error Lookup PinmemberTarundeep Singh Kalra17:20 24 Mar '04  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120517.1 | Last Updated 24 Mar 2004
Article Copyright 2004 by Tarundeep Singh Kalra
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid