OBJRESULT function

Purpose

Return the result of the execution of the most recent OBJECT statement.

Syntax

lResult& = OBJRESULT

Remarks

If an OBJECT statement fails at run-time, the ERR system variable is set to an appropriate PowerBASIC error code.  This is usually Error 5 ("Illegal function call").  In such cases, you can use the OBJRESULT function to return the result (lResult&) of the last run-time OBJECT statement.

Numeric equates for most OBJRESULT errors can be found in the WIN32API.INC file, and are mostly prefixed with %E_, %CO_ and %OLE_.  The following list comprises a selection of the most common errors that may be encountered:

%S_OK

= &H0

%S_FALSE       

= &H1

%E_UNEXPECTED  

= &H8000FFFF&

%E_NOTIMPL     

= &H80004001&

%E_NOINTERFACE 

= &H80004002&

%E_POINTER     

= &H80004003&

%E_ABORT       

= &H80004004&

%E_FAIL        

= &H80004005&

%E_ACCESSDENIED

= &H80070005&

%E_HANDLE      

= &H80070006&

%E_OUTOFMEMORY 

= &H8007000E&

%E_INVALIDARG  

= &H80070057&

As can be seen from the above error list, a large numeric error code can be cryptic.  However, we can translate the OBJRESULT error code into a verbose error message using the FormatMessage API function.  This can be most helpful especially during application development and debugging

See also

DIM, CLSID$, GUID$, GUIDTXT$, INTERFACE/END INTERFACE, ISNOTHING, ISOBJECT, OBJECT, OBJACTIVE, OBJPTR, PROGID$, SET

Example

' Uses MAKELANGID() function in WIN32API.INC

DIM A AS ASCIIZ * 1024

CALL FormatMessage(%FORMAT_MESSAGE_FROM_SYSTEM, _

  BYVAL 0&, OBJRESULT, BYVAL MAKELANGID( _

  %LANG_NEUTRAL, %SUBLANG_DEFAULT), _

  A, SIZEOF(A), BYVAL 0&)

' A will contain a verbose system error message