What is an hResult?

Methods may optionally have an explicit return value which you specifically declare.  However, in addition to this, all Automation or Dispatch Methods and Properties have another "Hidden Return Value", which is cryptically named hResult.  While the name would imply a handle for a result, it's really not a handle at all, but just a long integer value, used to indicate the success or failure of the Method. After calling a Method or Property, you can retrieve the hResult value with the  PowerBASIC function OBJRESULT.  The most significant bit of the value is known as the severity bit.  That bit is 0 (value is positive) for success, or 1 (value is negative) for failure.  The remaining bits are used to convey error codes and additional status information.  If you call any object Method/Property (either Dispatch or Direct), and the severity bit in the returned hResult is set, PowerBASIC generates Run-Time error 99: Object error.  When you create a Method or Property, PowerBASIC  automatically returns an hResult of zero, which implies success.  You can return a non-zero hResult value by executing a METHOD OBJRESULT = expr within a Method, or PROPERTY OBJRESULT = expr within a Property.

 

See Also

What is an object, anyway?

Just what is COM?

How do you create an object?

How do you register a COM Component?