p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   VS.NET 2002/2003 (http://p2p.wrox.com/forumdisplay.php?f=103)
-   -   Define events in COM built in .NET (http://p2p.wrox.com/showthread.php?t=5305)

roy October 22nd, 2003 08:46 PM

Define events in COM built in .NET
Hi everyone.
I built in .NET a 'class library' project , which then I
compiled with "Register for COM interop".
I also added some events.

I use this component in VB6, but I can't hook up to the
Can someone please help?

In the .NET component's code, I tried to define events in
      2 different ways:
  public delegate void ClickedEventHandler(string val);
  public event ClickedEventHandler Clicked;
  and then...
  if(Clicked!=null) Clicked(txt.value);

2. [InterfaceTypeAttribute
    public interface IMonitorEvent
         void HandleMonitorEvent(bool IsEmergency);

Then, in order to hook up to those events in VB6:
1. I added a refernce in VB6 to the component.
2. I created instance
    Dim MyObj As ContainerForIE.Form1
    Set MyObj = CreateObject("ContainerForIE.Form1")
3. I tried to use
   "Public WithEvents MyObj As ContainerForIE.Form1"
   But it raises an error "Object does not source
   automation events"

Can anyone help please?

roy October 22nd, 2003 11:07 PM

You need to basically declare an interface, provide a GUID to that
interface, make it IDispatch based and use ComSourceInterfaces() to
assign that interface as the event interface. Then use delegates to
point to the methods exposed by the interface.

If you did not understand what I am talking about, check out MSDN for
"Raising Events handled by COM Sink" topic. In VS.NET 2003 its in,

All times are GMT -4. The time now is 09:35 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.