CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2001
    Location
    Czech Republic
    Posts
    78

    Catching events from a COM object in an ActiveX control

    I have a MFC ActiveX control which displays data from a COM object (which is in a separate DLL). I want to be able to catch events fired from this object. I tried to derive the ActiveX implementation class from the IDispEventImpl class and add an event sink map, but when the event is fired I get a crash in the CComCriticalSection::Lock() method. I suppose this is due to the fact the ActiveX is not a regular COM object.

    An interesting thing is that the crash appears only the first time an event is fired. The subsequent firings are all OK. I was tracing the code and found out that this occurs in CComTypeInfoHolder::GetTI(LCID lcid, ITypeInfo** ppInfo) (in atlcom.h file) because the m_pInfo member is initially NULL and the GetTI(lcid) method (in which the crash appears) is called. After that the m_pInfo member is filled and the code works.

    Any thoughts how to solve this?

  2. #2
    Join Date
    Mar 2001
    Location
    Czech Republic
    Posts
    78

    Resolved Re: Catching events from a COM object in an ActiveX control

    Problem solved!

    The trick is to manually provide information about the event methods. So first in the header file for the ActiveX control declare one _ATL_FUNC_INFO object for each event in the sink map:
    Code:
    extern _ATL_FUNC_INFO OnMyEventInfo;
    The declaration must not be inside the class definition.

    Then in the implementation file fill these object with the correct information:
    Code:
    _ATL_FUNC_INFO OnMyEventInfo = {CC_STDCALL, VT_EMPTY, 0, {}};
    (the values will be different for your methods)

    Finally, use the SINK_ENTRY_INFO macros instead of SINK_ENTRY_EX ones in the sink map:
    Code:
    	
    BEGIN_SINK_MAP(CReportCtrl)
      SINK_ENTRY_INFO(101, DIID__IMyObjectEvents, 1, OnMyEvent, &OnMyEventInfo)
    END_SINK_MAP()
    And that's it

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured