All Frameworks  Class Hierarchy  This Framework  Indexes

System Typedef HRESULT

typedef int HRESULT
Return type for the QueryInterface method, and for most interface methods.

Role: This type allows you to analyze the result of a call for the QueryInterface method and for most interface methods.
  1. In the case of the QueryInterface method


  2. To test the result, always use the macros SUCCEEDED and FAILED.
    
      IMyInterface * pIMyInterface = NULL ;
      HRESULT rc = pIMyOtherInterface->QueryInterface(IID_IMyInterface,(void**) &pIMyInterface);
     
      //Test with SUCCEEDED macro:
      
      if ( SUCCEEDED(rc) )
      {
          // In this case, rc is S_OK
          // pIMyInterface is valid 
          ....
      }
    
      //Test with FAILED macro
    
      if ( FAILED(rc) )
      {
          // In this case, rc is E_NOINTERFACE or E_UNEXPECTED
          // pIMyInterface is not valid 
      }
    
     
  3. In the case of an interface method


  4. You can use the macros SUCCEEDED and FAILED or test directly the value to have more details. Refer to the method documentation to know about its possible HRESULT values.
      IMyInterface * pIMyInterface = NULL ;
      HRESULT rc = pIMyOtherInterface->QueryInterface(IID_IMyInterface,(void**) &pIMyInterface);
      if ( SUCCEEDED(rc) )
      {
          // rc = S_OK
          rc = pIMyInterface->Method();
          
          // Test with SUCCEEDED macro
    
          if ( SUCCEEDED(rc) )
          {
             // In this case, rc is S_OK or S_FALSE   
             // You can directly test the rc value  
             if ( S_FALSE == rc )
             {
                    ...
             }else
             {
                    ....
             }
          }
    
          // Test with FAILED macro
    
          if ( FAILED(rc) )
          {
             // In this case, rc is E_xxxxx 
             // You can directly test the rc value, 
             if ( E_FAIL == rc )
             {
                   ....
             }
             ....
          }
      }
     
The possible values are:
Values:
S_OK
Method succeeded. In some contexts, it means additionally that the function returns a boolean true.
S_FALSE
Method succeeded. In some contexts, it means additionally that the function returns a boolean false.
E_FAIL
Unspecified failure.
E_NOINTERFACE
Component does not support the requested interface.
E_UNEXPECTED
For an unexpected failure.
E_NOTIMPL
Method is not implemented.
E_OUTOFMEMORY
Required memory can not be allocated.

This object is included in the file: IUnknown.h

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