It would be better if we had some source code at hand. Specifically the Delphi declaration of the COM interface.
My guess is that the method is declared as safecall
. What this means is that the compiler understands that the method is actually stdcall
returning HRESULT
, and re-writes the parameters to match. If the true COM method returns an HRESULT
other than S_OK
then the compiler writes code to check for that and convert the error into an exception.
The exception that is raised will be EOleSysError
and that has the property ErrorCode
which contains the HRESULT
that you are looking for.
So, you need to:
- Add an exception handler to catch
EOleSysError
. - Read the
ErrorCode
property of theEOleSysError
exception instance that you catch.
This is all a little bit round the houses. If you'd prefer to avoid exception handling, then you can always re-write the COM interface declaration to be a true stdcall
method returning an HRESULT
.