Larry Osterman's WebLog

Confessions of an Old Fogey
Blog - Title

How do you know what a particular error code means?

How do you know what a particular error code means?

Rate This
  • Comments 16

So you're debugging your program, and all of a sudden you get this wierd error code - say error 0x00000011.  How do you know what that message means?

Well, one way is to memorize the entire Win32 error return code set, but that's got some issues.

Another way, if you have the right debugger extension is to use the !error extension - it will return the error text associated with the error.  There's a similar trick for dev studio (although I'm not sure what it is since I don't use the devstudio debugger)

But sometimes you're not running under windbg or devstudio and you've got a Win32 error code to look up.

And here's where the clever trick comes in.  You see, there's a complete list of error codes built into the system.  It's buried in the NET.EXE command that's used for network administration.

If you type "NET HELPMSG <errorno>" on the command line, you'll get a human readable version of the error code. 

So:

C:\>net helpmsg 17
The system cannot move the file to a different disk drive.

It's a silly little trick, but I've found it extraordinarily useful.

 

  • FYI: net helpmsg does not know about COM errors (and more I guess). A nice utility available for download at Microsoft.com is "err" [1], which knows about those too.

    [1] http://www.microsoft.com/downloads/details.aspx?FamilyId=BE596899-7BB8-4208-B7FC-09E02A13696C&displaylang=en
  • Andreas, it does. You just need to type the HRESULT in as a decimal number.
  • >> Well, one way is to memorize the entire Win32 error return code set, but that's got some issues. <<

    Haha. The primary issue being not everyone's a Raymond.
  • Oh, it does? Either I've misunderstood the hex to decimal conversion or my version doesn't support that :(

    Here is the output I get for some attempts (note that I removed some whitespace and "$ " is the prompt):

    1) Just try the hex-HRESULT
    $ net helpmsg 0x80004002
    The syntax of this command is:
    NET HELPMSG
    message#

    [Does not work, as expected based on your comment above]
    2) Convert the hex to decimal and run it again
    $ net helpmsg -2147467262
    The syntax of this command is:
    NET HELPMSG
    message#

    [Huh, shouldn't this work??]

    3) Decimal with 'err'
    $ err -2147467262
    Error string for error -2147467262 (0x80004002) is:
    No such interface supported

    4) Hex with 'err'
    $ err 0x80004002
    Error string for error -2147467262 (0x80004002) is:
    No such interface supported
  • Andreas, net only takes unsigned integers, not signed integers. Having said that, trying the unsigned version of 0x80004002 still fails.

    Which implies that the error text isn't wherever FORMAT_MESSAGE_FROM_SYSTEM gets it.
  • The way to do it in visual studio is to append ",hr" (without quotes) to the variable that contains an error code. Very useful, can also accept hex.

    In fact, something I didn't know about VC6 (yes, I still use VC6) until recently is that you can create your own watch strings by writing a simple extension..
  • I think it's kind of awesome that for all the errors across the win32 system none were reused. (As far as I know.) How did you keep track of that? Did every product group get a chunk of error codes to assign as they saw fit?
  • foxyshadis: It's actually quite simple. There's a single header file winerror.h that's checked into the tree.

    Everyone who contributes to the base project and adds error codes to the base codebase (and that's a relatively limited set of people) modifies the same source file. So no collisions.

    The other product groups have their own header files that define their own error codes, if they're using COM they use the facility codes to differentiate between the products.
  • Mike said:
    The way to do it in visual studio is to append ",hr" (without quotes) to the variable that
    contains an error code. Very useful, can also accept hex.

    Another useful tip for Visual Studio is the psuedo-register ERR. It contains the result of calling GetLastError(). Putting "ERR,hr" in your watch window is a useful way to find out why the last API failed.
  • I have a program downloaded from Microsoft somewhere called "errlook" that allow you to specify the module to look for an error code.

    If no module is specified, Win32 error code is assumed.

    Very handy indeed.
  • @ERR,hr and @EAX,hr are always at the top of my watch list in VC. errlook.exe is a nice util because you can get string descriptions of errors where the strings are in other DLLs (from message table resources I suppose). So you can use it to get a string for error 12001 from wininet.dll.
  • Start - Programs - Microsoft Visual Studio 6.0 - Microsoft Visual Studio 6.0 Tools - Error Lookup
    invokes ERRLOOK.EXE which gives the same information.

    If both VS6 and VS2003 are installed then ERRLOOK.EXE still works, but VS2003 takes control of it and weirds up the GUI. Minimizing, restoring, disappearing from the Windows taskbar, etc. Can't find out what errors are occuring in the GUI because no one's displaying an error number to look up.
  • This time from Larry Osterman:

    If you type &quot;NET HELPMSG &amp;lt;errorno&amp;gt;&quot; on the command line, you'll...
  • I used to use "Visual C++ error lookup" tool of visual studio.

    It would be better if "net helpmsg 0x00000011" works.
  • Two tools you should be aware of:

    Courtesy of John Durant, in his mention of BillG's talking about...
Page 1 of 2 (16 items) 12