Events from ActiveX controls added at run time 
Author Message
 Events from ActiveX controls added at run time

I am connecting at run time to an ActiveX EXE that was
written in Visual Basic.  I am able to call methods and
access properties in the ActiveX object but have not been
able to figure out how to get notified of events triggered
by the ActiveX EXE.  The wrapper class that was created
when I added the ActiveX object to the project has
function of with the names of the events I am trying to
get, but they are not called.  Any suggestions would be
greatly appreciated.

Wed, 28 Jul 2004 05:24:00 GMT  
 Events from ActiveX controls added at run time
Hi Scott,
    I am assuming that you have a .NET client as it was not clear from your
post.  There are two ways to sink COM events in .NET:
1. Using the COM connection Points

public class CSink : COMSrvLib._IInteropTestEvents
           public void MyEvent1(uint one)

            public void MyEvent2(uint two)

static void Main(string[] args)
     COMSrvLib.InteropTestClass Obj = new COMSrvLib.InteropTestClass();
     UCOMIConnectionPointContainer pConPtCon =
     UCOMIConnectionPoint pConPt;
     Guid guid = new Guid("XXXXXXXXXXX-WHATEVER"); //IID describes a
supported outgoing interface.

      pConPtCon.FindConnectionPoint(ref guid, out pConPt);

      CSink e = new CSink();
      int dwCookie;
      pConPt.Advise(e, out dwCookie);

     //Call the method


2. Delegate-Event approach
static void OnMyEvent1(uint one)
           Console.WriteLine("MyEvent1 called");

static void OnMyEvent2(uint two)
            Console.WriteLine("MyEvent2 called");


//Create a delegate for the method in the event interfacce and point it to
your implementation
COMSrvLib._IInteropTestEvents_MyEvent1EventHandler DMyEvent1 = new
//Call Advise
Obj.MyEvent1 += DMyEvent1;

COMSrvLib._IInteropTestEvents_MyEvent2EventHandler DMyEvent2 =  new
Obj.MyEvent2 += DMyEvent2;

//Call the method.

Hope that helps

Chetan Parmar[MSFT]
This posting is provided AS IS with no warranties, and confers no rights.

Wed, 28 Jul 2004 08:32:59 GMT  
 [ 2 post ] 

 Relevant Pages 

1. Adding controls to a dialog at run-time

2. add ocx control in run time

3. Adding controls at run-time

4. Q:How to add event handle code for an Activex control

5. run time licensing for activex controls

6. How do I get the URL from activeX control at run time

7. Handling ActiveX control events without an ActiveX container

8. add Activex control to Activex container daynamically

9. How to add ActiveX controls to a Activex DLL

10. Controlling an event of an ActiveX control

11. Adding a new control to an existing ActiveX Control project

12. Event Handler at Run Time?


Powered by phpBB® Forum Software