Wednesday, May 19, 2010

[C++][引用] Interpreting HRESULT Values

In the Microsoft® Windows® operating system, error codes are returned as signed 32-bit HRESULT values that indicate the status of an operation. The high-order sign bit indicates success or failure of the particular method function call.

Interpreting HRESULTs

The HRESULT data type is composed of fields depicted by the following diagram:

Bb401631.f3689902-86e5-404d-be3a-b743af20a2ad(en-us,MSDN.10).gif

The 32-bit value is used to describe an error or warning and is composed of a 1-bit code that indicates the severity (S) of the condition; 0 for success and 1 for failure. The severity code is followed by 4 reserved bits depicted as R, C, N, and r, and then by an 11-bit facility code that indicates responsibility for the error or warning that is defined in the method implementation.

The Facility codes and Error codes are defined by the Winerror.h header file. The following table lists some typical HRESULT values:

Return value/codeDescription

0x00000000
S_OK

Operation successful

0x80004001
E_NOTIMPL

Not implemented

0x80004002
E_NOINTERFACE

Interface not supported

0x80004004
E_ABORT

Operation aborted

0x80004005
E_FAIL

Unspecified failure

0x80070057
E_INVALIDARG

One or more arguments are invalid

For more information about HRESULT, Facility Codes (Codes in FACILITY_ITF), and mapping Win32 error values (HRESULT_FROM_WIN32) into an HRESULT, see Microsoft Developer Network (MSDN).

Note Because error codes are implementation specific, two identical HRESULTs that are returned from two different interfaces can have different meanings.

Interpreting HRESULT Values

No comments:

Labels