Problem with adding custom event to a COM (ActiveX) Control
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Problem with adding custom event to a COM (ActiveX) Control

  1. #1
    Join Date
    Aug 2009
    Posts
    2

    Problem with adding custom event to a COM (ActiveX) Control

    I'm really new in all this so forgive if the some parts of the question are stupid.
    I'm having an ActiveX control (say abc) which is instantiated from an html page using its CLSID. It is having some properties as well as events. (Which we catch by simple JScript 'for' and 'event' attributes. )

    Now, this class inherits from/implements a lot of interfaces and classes like CComObjectRootEx<CComSingleThreadModel>, CComCoClass, CComControl, IDispatchImpl, IConnectionPointContainerImpl etc. etc. and also the almost standard CProxy_abcEvents class (which in turn inerits from IConnectionPointImpl and the interface which defines the Events in form 'Fire_OnSomethingHappened'). This same class also provides a method called 'CoCreateInstance' which we used to create another com object xyz which provided only properties and no events.

    The problem started when I now need to add an event to this other Com object also. So I added the event in the idl file, created another CProxy_xyzEvents class for itself and added the new event in that class, added this proxy to CONNECTION_POINT_MAP and inherited this com class from a number of other interfaces. Also made COM_INTERFACE_ENTRY for IConnectionPointContainer etc.

    All this compiles well, but I'm still not getting the event fired when desired.

    I noticed that though for the original control 'Advise ()' method is called internally (from mshtml.dll), my new control xyz's Advise method never gets called. Do I need to call that manually? If yes, how do I get the correct IUnknown pointer for that? I'm guessing if I have to call it, I'd need to do that in the CoCreateInstance() of class abc control which creates xyz.

    I still don't know if I'm missing inheriting from some other implementations/interfaces.

    Thanks a lot for helping !

  2. #2
    Join Date
    Nov 2004
    Posts
    133

    Re: Problem with adding custom event to a COM (ActiveX) Control

    Hi Piyush,

    You have to do the following changes to the CoClass,
    Derive from

    public IProvideClassInfo2Impl<&CLSID_MyCalss,& __uuidof(_IMyEvents),&LIBID_MYCOMP_Lib>


    then add the following macros to the

    BEGIN_COM_MAP(CAsyncEventConsumer)
    //Add this two macros in to this map
    COM_INTERFACE_ENTRY(IProvideClassInfo)
    COM_INTERFACE_ENTRY(IProvideClassInfo2)
    END_COM_MAP()


    Then try, it should work.


    Regards
    Pradish

  3. #3
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    5,933

    Re: Problem with adding custom event to a COM (ActiveX) Control

    Quote Originally Posted by piyush_soni View Post
    ... (Which we catch by simple JScript 'for' and 'event' attributes. )

    ...I noticed that though for the original control 'Advise ()' method is called internally (from mshtml.dll), my new control xyz's Advise method never gets called.
    Exactly. The original control instance is created while the page gets built in browser, so there is a direct way to bind event interface. But the other control instance gets created long after the page appears constructed, and all the bindings already left in the past... you see?
    Best regards,
    Igor

Tags for this Thread

Posting Permissions

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


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center