Regardless of whether the parameter is declared as [out]
or [out, retval]
the HRESULT
will be returned to the caller side. What happens next greatly depends on the middleware between the actual caller code and COM.
If it's .NET code then the HRESULT
will be checked by the .NET generated wrapper and an exception will be thrown and the only solution is to catch and interpret exceptions which can be a lot of pain because different HRESULT
s will be translated to different exceptions.
If it's something more old school like for example Visual C++ Native COM support then you have options. The default is that Native COM Support generates a wrapper for each method with [out, retval]
parameter which now returns the type of that parameter and HRESULT
is checked inside the wrapper and perhaps _com_issue_error()
is called to throw an exception and the original HRESULT
is passed into _com_issue_error()
and the exception object from where you can retrieve it. It can be that handling exceptions for every COM method call adds clutter to your code and then you can use raw_interfaces_only
with #import
directive and then now wrappers are generated - you will have the original interface presented to you. It's up to you which you choose - HRESULT
s checked inside wrappers or having no wrappers.
Anyway you will have means to know there was an error. Using [out, retval]
is by no means a bad practice.