Extended error info on an ActiveX method (BCB vs VC)


How do you manage to return extended error information (ie hr = E_FAIL and
why) in an activeX method?

Say i have a method called "AddImage". You send it the path of the image

STDMETHODIMP CListAx::AddImage(BSTR FilePath, long *pImageIndex)
    HRESULT hr = S_OK;

    // Check if the path exist, if not we have a failure
    if( CheckPathExist(FilePath) == false )
        hr = E_FAIL;

    // Lots of code (not important here)

    // Finally we return the result
    return hr;


Now we can see that if the path doesn't exist we return E_FAIL, otherwise we
return S_OK. This is all fine so far except that if we look at the generated
method when we import the activeX in BCB we get this

// *_OCX.cpp file
void __fastcall TListAx::AddImage(BSTR FilePath/*[in]*/, long*
  GetDefaultInterface()->AddImage(FilePath/*[in]*/, pImageIndex/*[out]*/);


I fail to see how i can determine the result of the code. How am i suppose
to get the HRESULT code if all my method return nothing?

Now in VC++ you get something like that :

// In the generated class of the activeX
void CListAx::AddImage(LPCTSTR FilePath, long* pImageIndex)
 static BYTE parms[] =
 InvokeHelper(0x1b, DISPATCH_METHOD, VT_EMPTY, NULL, parms,
   FilePath, pImageIndex);


// In *.tli file
inline HRESULT IListAx::AddImage ( _bstr_t FilePath, long * pImageIndex ) {
    HRESULT _hr = raw_AddImage(FilePath, pImageIndex);
    if (FAILED(_hr)) _com_issue_errorex(_hr, this, __uuidof(this));
    return _hr;


So if there is an error, you get a messagebox that will try to get the
ErrorInfo object content (normally empty unless you set it). So i know if
there is a failure and VC++ display it to me without any intervention from

Why can't BCB do that?

The only thing i can do right now is use the _com_raise_error to throw a COM
exception and the user will have to catch it.

   myPtr->AddImage(WideString("Some path"), &myIndex);
  catch( _com_error &e )
   bstrDescription = (wchar_t*)e.Description();
   bError = true;

  if( bError )

Isn't there a less drastic solution out there that won't require try catch
at every method?

Thank you in advance,

Francois Belair