iCAx开思网

标题: CAA CATIA::About HRESULT [打印本页]

作者: Kama_Goon    时间: 2005-1-14 17:26
标题: CAA CATIA::About HRESULT
About HRESULT
HRESULT is a Microsoft specific return value to report execution conditions to calling functions. QueryInterface in both COM and CNext returns an HRESULT. The methods you expose in your interfaces should also return an HRESULT. They so become OLE compliant.
  
HRESULT is encoded on 32 bits and is divided into three areas. The first bit is the severity and reports whether the method called succeeds or fails. The following 15 bits contain the facility code which gives information about the type and the origin of the return code, and the last 16 bits contain the actual return code the method is returning. Here is a map of the HRESULT's structure.
  
Common HRESULT codes fall in the following categories. A successful return code contains S_ in its name, while a failure code contains E_ in its name.  
  
S_OK to report that the function succeeds  
S_FALSE to report that the function succeeds, but returns the boolean value False  
E_NOINTERFACE returned by QueryInterface to report that the queried object doesn't support the requested interface  
E_UNEXPECTED to report an unexpected failure  
E_OUTOFMEMORY to report that the function called cannot allocate the required memory  
E_FAIL to report an unspecified failure.  
[Top]
  
How to Test a Returned HRESULT?
You should never test the HRESULT value, but use the SUCCEEDED or FAILED macros as follows:
  
HRESULT rc = pCATBaseUnKnownOnComp->QueryInterface(IID_CATIXX,
                                                   (void**) [$pIXXOnComp)]
if (FAILED(rc))
{
  ... // Process the error
}
else if (SUCCEEDED(rc))
{
  pIXXOnComp->MXX1();
  ...




欢迎光临 iCAx开思网 (https://www.icax.org/) Powered by Discuz! X3.3