Return Value of COM interface hresult processing and error Query

Source: Internet
Author: User
The hresult returned from the com method is a 32-bit signed integer. Its non-negative value indicates success, and the negative value indicates failure. Hresult has three fields: Level (indicating success or failure), function code, and status code. The function code indicates the components or Program . Microsoft assigns function codes to different components, such as COM and task scheduling programs. The function code is a 16-bit value. It only has no other internal meaning. It is randomly associated between numbers and meanings. It is similar to the value returned by getlasterror.
If you find an error in the winerror. h header file Code , You will see many hresult values listed according to the [function] _ [degree] _ [description] naming convention, and the general hresult (like e_outofmemory) returned by the component does not have a function code in the name. For example:

Regdb_e_readregdb:
Function Code = regdb, which refers to "registry database )";
Degree = e indicates an error );
Description = readregdb is a description of the error (meaning the registry database cannot be read ). S_ OK: no function code -- General (generic)
Hresult;
Degree = s; success );
"OK" indicates that everything is fine (everything's OK ).

1. Error lookup tool
You can use the error lookup tool provided by VC to easily find the built-in function code for hresult. For example, assume that you forgot to call coinitialize () before cocreateinstance (). The value returned by cocreateinstance () is 0x800401f0. You only need to enter this value to the error search tool and press the "look up" button to see the error message description "coinitialize not called", as shown in:

2. Watch window query:
Another method to find the description of hresult is in the debugger. Assume that the hresult variable is hres. Enter "hres, HR" in the Left box of the Watch window to indicate the value to be viewed. "HR" will notify VC to display the value described by hresult. As shown in:

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.