none
ACTIVEX returns E_FAIL, but no exception in the calling .NET (C#) RRS feed

  • Question

  • I have an ACTIVEX object (created in C++)

    .odl:   
        dispinterface _DmyCtrl
        ....
       [id(90)] HRESULT MoveComponents([in] BSTR trgFolderRefId, [in] VARIANT handlesToMove);


    .cpp
    BEGIN_DISPATCH_MAP(myCtrl, COleControl)
      DISP_FUNCTION(myCtrl, "MoveComponents", MoveComponents, VT_I4, VTS_BSTR VTS_VARIANT)
    END_DISPATCH_MAP()
    HRESULT myCtrl::MoveComponents(LPCTSTR trgFolderRefId, const VARIANT FAR& handlesToMove)
    { ...   return E_FAIL;
    }
    I run TLBIMP.EXE, and use the created interop DLL to call it from C#

    Interop_myCtrl.myCtrl myCtrl = ....
    myCtrl .MoveComponents(folderTrg.getRefId(), refIDs.ToArray());

    And here I supposed to have exception due to E_FAIL, but nothing, code just runs through it as it would be S_OK

    Anyone has any idea?
    Thanks!
    Tuesday, March 16, 2010 11:17 AM

All replies

  • 1) Set a brekpoint into your MoveComponents method and debug your app. Can you reach the breakpoint?
    2) Check from which path is your DLL loaded (maybe different copy is used which doesn't return E_FAIL).

    -Karel
    Tuesday, March 16, 2010 4:27 PM
    Moderator
  • Hello Karel,

    yes, it's called, and the correct DLL is loaded.
    I debuged, and found that this MoveComponents is called from
    c:\Program Files\Microsoft Visual Studio 9.0\VC\atlmfc\src\mfc\oledisp1.cpp
    SCODE CCmdTarget::CallMemberFunc( const AFX_DISPMAP_ENTRY* pEntry, WORD wFlags, VARIANT* pvarResult, DISPPARAMS* pDispParams, UINT* puArgErr)

    Here pvarResult is NULL, (passed by COleDispatchImpl::Invoke(...))
    If it would not be NULL, then the returning value E_FAIL would be copied to pvarResult->scode.
    I think this would be used(?) by .NET framework to create exception. But this is NULL, so CallMemberFunc() ignores the retval, and return S_OK.

    I have a workaround (create a 'success' output parameter, or throw COleDispatchException.
    But anyway, strange...
    Tuesday, March 16, 2010 5:11 PM