// //
// COM Error Codes //
// //
//
// The return value of COM functions and methods is an HRESULT.
// This is not a handle to anything, but is merely a 32-bit value
// with several fields encoded in the value. The parts of an
// HRESULT are shown below.
//
// Many of the macros and functions below were orginally defined to
// operate on SCODEs. SCODEs are no longer used. The macros are
// still present for compatibility and easy porting of Win16 code.
// Newly written code should use the HRESULT macros and functions.
//
//
// HRESULTs are 32 bit values layed out as follows:
//
// 3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
// 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
// +-+-+-+-+-+---------------------+-------------------------------+
// |S|R|C|N|r| Facility | Code |
// +-+-+-+-+-+---------------------+-------------------------------+
//
// where
//
// S - 严重性 - 表明成功或者失败
//
// 0 - 成功
// 1 - 失败 (COERROR)
//
// R - reserved portion of the facility code, corresponds to NT's
// second severity bit.
//
// C - reserved portion of the facility code, corresponds to NT's
// C field.
//
// N - reserved portion of the facility code. Used to indicate a
// mapped NT status value.
//
// r - reserved portion of the facility code. Reserved for internal
// use. Used to indicate HRESULT values that are not status
// values, but are instead message ids for display strings.
//
// Facility - 设备码
//
// Code - 设备状态码
//
//
// Severity values
//
//成功
#define SEVERITY_SUCCESS 0
//失败
#define SEVERITY_ERROR 1
//
// Generic test for success on any status value (non-negative numbers
// indicate success).
//
//严重性成功,就认为成功
#define SUCCEEDED(Status) ((HRESULT)(Status) >= 0)
//
// and the inverse
//
//严重性失败,就认为失败
#define FAILED(Status) ((HRESULT)(Status)<0)
//
// Generic test for error on any status value.
//
//判断COM调用成功或者失败
#define IS_ERROR(Status) ((unsigned long)(Status) >> 31 == SEVERITY_ERROR)
//
// Return the code
//
//取设备状态码
#define HRESULT_CODE(hr) ((hr) & 0xFFFF)
#define SCODE_CODE(sc) ((sc) & 0xFFFF)
//
// Return the facility
//
//取设备码
#define HRESULT_FACILITY(hr) (((hr) >> 16) & 0x1fff)
#define SCODE_FACILITY(sc) (((sc) >> 16) & 0x1fff)
//
// Return the severity
//
//取严重性
#define HRESULT_SEVERITY(hr) (((hr) >> 31) & 0x1)
#define SCODE_SEVERITY(sc) (((sc) >> 31) & 0x1)
//
// Create an HRESULT value from component pieces
//
//生成HRESULT
#define MAKE_HRESULT(sev,fac,code) \
((HRESULT) (((unsigned long)(sev)<<31) | ((unsigned long)(fac)<<16) | ((unsigned long)(code))) )
#define MAKE_SCODE(sev,fac,code) \
((SCODE) (((unsigned long)(sev)<<31) | ((unsigned long)(fac)<<16) | ((unsigned long)(code))) )
// ****** OBSOLETE functions
// HRESULT functions
// As noted above, these functions are obsolete and should not be used.
// Extract the SCODE from a HRESULT
//HRESULT TO SCODE
#define GetScode(hr) ((SCODE) (hr))
// Convert an SCODE into an HRESULT.
//SCODE TO HRESULT
#define ResultFromScode(sc) ((HRESULT) (sc))
// ****** End of OBSOLETE functions.
// ---------------------- HRESULT value definitions -----------------
//
// HRESULT definitions
//
#ifdef RC_INVOKED
#define _HRESULT_TYPEDEF_(_sc) _sc
#else // RC_INVOKED
#define _HRESULT_TYPEDEF_(_sc) ((HRESULT)_sc)
#endif // RC_INVOKED
//无错误
#define NOERROR 0
//
// Error definitions follow
//
//错误的严重性都是失败,即SEVERITY_ERROR 1,0X8.......L
//
// Codes 0x4000-0x40ff are reserved for OLE
//
//
// Error codes
//
//
// MessageId: E_UNEXPECTED
//
// MessageText:
//
// Catastrophic failure
//
#define E_UNEXPECTED _HRESULT_TYPEDEF_(0x8000FFFFL)
#if defined(_WIN32) && !defined(_MAC)
//
// MessageId: E_NOTIMPL
//
// MessageText:
//
// Not implemented
//
#define E_NOTIMPL _HRESULT_TYPEDEF_(0x80004001L)
//
// MessageId: E_OUTOFMEMORY
//
// MessageText:
//
// Ran out of memory
//
#define E_OUTOFMEMORY _HRESULT_TYPEDEF_(0x8007000EL)
//
// MessageId: E_INVALIDARG
//
// MessageText:
//
// One or more arguments are invalid
//
#define E_INVALIDARG _HRESULT_TYPEDEF_(0x80070057L)
//
// MessageId: E_NOINTERFACE
//
// MessageText:
//
// No such interface supported
//
#define E_NOINTERFACE _HRESULT_TYPEDEF_(0x80004002L)
//
// MessageId: E_POINTER
//
// MessageText:
//
// Invalid pointer
//
#define E_POINTER _HRESULT_TYPEDEF_(0x80004003L)
//
// MessageId: E_HANDLE
//
// MessageText:
//
// Invalid handle
//
#define E_HANDLE _HRESULT_TYPEDEF_(0x80070006L)
//
// MessageId: E_ABORT
//
// MessageText:
//
// Operation aborted
//
#define E_ABORT _HRESULT_TYPEDEF_(0x80004004L)
//
// MessageId: E_FAIL
//
// MessageText:
//
// Unspecified error
//
#define E_FAIL _HRESULT_TYPEDEF_(0x80004005L)
//
// MessageId: E_ACCESSDENIED
//
// MessageText:
//
// General access denied error
//
#define E_ACCESSDENIED _HRESULT_TYPEDEF_(0x80070005L)
#else
//
// MessageId: E_NOTIMPL
//
// MessageText:
//
// Not implemented
//
#define E_NOTIMPL _HRESULT_TYPEDEF_(0x80000001L)
//
// MessageId: E_OUTOFMEMORY
//
// MessageText:
//
// Ran out of memory
//
#define E_OUTOFMEMORY _HRESULT_TYPEDEF_(0x80000002L)
//
// MessageId: E_INVALIDARG
//
// MessageText:
//
// One or more arguments are invalid
//
#define E_INVALIDARG _HRESULT_TYPEDEF_(0x80000003L)
//
// MessageId: E_NOINTERFACE
//
// MessageText:
//
// No such interface supported
//
#define E_NOINTERFACE _HRESULT_TYPEDEF_(0x80000004L)
//
// MessageId: E_POINTER
//
// MessageText:
//
// Invalid pointer
//
#define E_POINTER _HRESULT_TYPEDEF_(0x80000005L)
//
// MessageId: E_HANDLE
//
// MessageText:
//
// Invalid handle
//
#define E_HANDLE _HRESULT_TYPEDEF_(0x80000006L)
//
// MessageId: E_ABORT
//
// MessageText:
//
// Operation aborted
//
#define E_ABORT _HRESULT_TYPEDEF_(0x80000007L)
//
// MessageId: E_FAIL
//
// MessageText:
//
// Unspecified error
//
#define E_FAIL _HRESULT_TYPEDEF_(0x80000008L)
//
// MessageId: E_ACCESSDENIED
//
// MessageText:
//
// General access denied error
//
#define E_ACCESSDENIED _HRESULT_TYPEDEF_(0x80000009L)
#endif //WIN32
//
// MessageId: E_PENDING
//
// MessageText:
//
// The data necessary to complete this operation is not yet available.
//
#define E_PENDING _HRESULT_TYPEDEF_(0x8000000AL)
//
// Success codes
//
//严重性都是成功,设备码为0 设备状态码【0成功 1失败】
//成功
#define S_OK ((HRESULT)0x00000000L)
//失败
#define S_FALSE ((HRESULT)0x00000001L)