Windows Error Code parsing

Source: Internet
Author: User

Read Catalogue

    • Windows API Error code parsing
    • Windows Exception Value Resolution
    • ErrLook Program
    • Resources

C or C + + development must often encounter a variety of error codes, because each error code is just an enumeration or an integer value, debugging or output log, can not know the specific meaning of the error code, this time you need to interpret this error code. For your own definition of the error code, you can parse it in its own way. For the Windows API error code, you need to call the Windows API for parsing, the following describes the specific error code resolution method.

Back to top of Windows API error code parsing

After the call to the Windows API fails, it is often necessary to obtain the corresponding error code through GetLastError, to resolve this error code to the corresponding description, you need to call another Windows API FormatMessage, the prototype is as follows:

Collapse
DWORD WINAPI FormatMessage (  _in_      DWORD dwFlags,  _in_opt_  lpcvoid lpsource,  _in_      DWORD Dwmessageid,  _in_      DWORD Dwlanguageid,  _out_     LPTSTR lpbuffer,  _in_      DWORD nSize,  _in_opt_  va_list *arguments);

The specific parameter meaning is not introduced here, the direct view of MSDN, the following is a detailed example of how to use:

Collapse
Char msg[1024] = {0}; FormatMessage (Format_message_from_system, NULL, 5, Lang_neutral, MSG, _countof (msg), null); cout << msg << Endl

Run the program to see the corresponding error description: Access denied .

Back to top Windows exception value resolution

When the program runs, it will inevitably produce some anomalies, through the Windows SEH mechanism can get this exception information, which will contain an outlier, such as 0xc0000008. If you use the FormatMessage method mentioned above, the message you get is a string, or you cannot get a description of this exception value. So how do I get a description of this outlier, and look closely at the MSDN documentation for the FormatMessage API, and you can see a flag like this:

Collapse
Format_message_from_hmodule

This flag means: You can use other modules to interpret this outlier or error code.

So what module will contain the definition and interpretation of Windows outliers, which can be known by Google or MSDN, is "Ntdll.dll".

Knowing this, you can write the program to explain the Windows outliers, the code is as follows:

Collapse
Char msg[1024] = {0}; Hmodule Hntdll = LoadLibrary ("NTDLL. DLL "); FormatMessage (Format_message_from_system | Format_message_from_hmodule,     Hntdll, 0xc0000008, Lang_neutral, MSG, _countof (msg), NULL); FreeLibrary (Hntdll); cout << msg << Endl;
Go back to the top of the ErrLook program

When you do need to parse Windows error codes and Windows outlier values in your program, you can use the methods above to parse them.

But when we simply want to see an explanation of the error code, do we have to write a program to explain it.

Microsoft also takes into account what you are thinking, so after installing VS, there is a gadget to explain the error code, called:ErrLook, which can be seen in the Tools menu of VS, or in the "vs Directory \common7\tools" Directory below to find this program, as follows:

Http://www.cnblogs.com/hbccdf/p/windows_error_code_parsing.html

Windows Error Code parsing

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.