HRESULT codes and other COM macros

Top  Previous  Next

Return codes from Inventor COM function calls are the normal COM codes.


Codes greater than or equal to 0 indicate success.
Codes less than 0 indicate failure.
You can use S_OK (defined as 0) to return you own HRESULT success code.
S_FALSE is also a success return code (S_ = success). It could be a simple question you asked COM, and does not fail.
You can use E_FAIL to return failure from your functions (E_=error)
You can also use E_INVALIDARG to return failure from your function (again E_=error)


These four macros are defined for you in WinError.h:


#define SUCCEEDED(hr) (((HRESULT)(hr)) >= 0)

#define FAILED(hr) (((HRESULT)(hr)) < 0)


#define S_OK      ((HRESULT)0L)

#define S_FALSE   ((HRESULT)1L)


You can sometimes get the text interpretation of the error by using _com_error in something like this:


   HRESULT hRes = pInvApp->get_ActiveDocument(&pDoc);

   if (FAILED(hRes)) {

       TRACE("Get Active Document Failed");


       return ;



You can also use ShowCOMError


Or you can use:


    TRACE("SetupDiGetDeviceInstanceId(): %s), _com_error(GetLastError()).ErrorMessage());


Some example codes (from one of the many Windows headers):


// Catastrophic failure


#define E_UNEXPECTED                     _HRESULT_TYPEDEF_(0x8000FFFFL)

#if defined(_WIN32) && !defined(_MAC)


// Not implemented

#define E_NOTIMPL                        _HRESULT_TYPEDEF_(0x80004001L)


// Ran out of memory

#define E_OUTOFMEMORY                    _HRESULT_TYPEDEF_(0x8007000EL)


// One or more arguments are invalid

#define E_INVALIDARG                     _HRESULT_TYPEDEF_(0x80070057L)


// No such interface supported

#define E_NOINTERFACE                    _HRESULT_TYPEDEF_(0x80004002L)


// Invalid pointer

#define E_POINTER                        _HRESULT_TYPEDEF_(0x80004003L)


// Invalid handle

#define E_HANDLE                         _HRESULT_TYPEDEF_(0x80070006L)


// Operation aborted

#define E_ABORT                          _HRESULT_TYPEDEF_(0x80004004L)


// Unspecified error

#define E_FAIL                           _HRESULT_TYPEDEF_(0x80004005L)


// General access denied error

#define E_ACCESSDENIED                   _HRESULT_TYPEDEF_(0x80070005L)



See also this page for the error manager.



Text, images and diagrams © 2021 Owen F. Ransen. All rights reserved. (But copy the source code as much as you want!)