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
events.
Can someone please help?
In the .NET component's code, I tried to define events in
2 different ways:
1."
public delegate void ClickedEventHandler(string val);
public event ClickedEventHandler Clicked;
and then...
if(Clicked!=null) Clicked(txt.value);
"
2. [InterfaceTypeAttribute
(ComInterfaceType.InterfaceIsDual)]
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")
MyObj.Show
"
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?
> Hi everyone.
> I built in .NET a 'class library' project , which then I
[quoted text clipped - 37 lines]
>
>
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,
ms-help://MS.MSDNQTR.2003FEB.1033/cpguide/html/cpconraisingeventshandledbycomsink.htm
HTH.
Gordz - 28 Jan 2004 21:40 GMT
I know this is a little late of a response, but I'd like to thank you Girish
for pointing me to the Microsoft article which showed how to set up events
in a COM Interop environment.
I've looked everywhere and obviously didn't use the correct keywords when
searching. This is the first example that actually showed the event
declarations and usage.
Regards,
Gord
roy wrote:
> Hi everyone.
> I built in .NET a 'class library' project , which then I
[quoted text clipped - 35 lines]
>
> Can anyone help please?
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,
ms-help://MS.MSDNQTR.2003FEB.1033/cpguide/html/cpconraisingeventshandledbyco
msink.htm
HTH.