3D PLM Enterprise Architecture

Middleware Abstraction - Object Modeler

What Is HRESULT?

A standard return value for all your interface methods
Quick Reference

Abstract

This article explains the HRESULT return value and shows how to test it using macros to take appropriate actions. It includes the following sections:


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.

CAASysHRESULT.gif (2896 bytes)

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.

[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();
  ...

[Top]


History

Version: 1 [Jan 2000] Document created
[Top]

Copyright © 2000, Dassault Systèmes. All rights reserved.