Discussion:
HOWTO: Exposing C# Events to ActiveX
(too old to reply)
amdrit
2009-10-21 05:54:47 UTC
Permalink
I am looking for the correct way, or most correct way to expose events from
a class object in C# for use by VB6.

I am receiving an error from the VB6 portion at runtime: Object or class
does not support the set of events - Which, according to an MS KB, means
that the event sink is not functioning properly even though at design time,
it all looks correct.

My scenario is based upon a bunch of reading on the web, and still this
solution is not working for me. One thing that troubles me is: Object
brower still doesn't see the interfaces, though the IDE forces me to
implement the whole interface in the class object.

So if anyone cares to point me into the correct direction, I'd be much
obliged. VS C# 2008 / Windows XP sp3, VB6 sp6

My currect solution is shaping up as thus:

[GuidAttribute("GUIDVALUEHERE")]
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
public interface IMethodsAndProperties
{
[DispID(1)]
Void MethodOne();
[DispID(2)]
Void MethodTwo();
[DispID(3)]
String PropertyOne {get;set;}
}

[GuidAttribute("GUIDVALUEHERE")]
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
public interface IEvents
{
[DispID(4)]
Void EventOne(string someValue);
}

public delegate void EventOneDelegate(string someValue);

[GuidAttribute("GUIDVALUEHERE")]
[ClassInterface(ClassInterfaceType.None)]
[ComSourceInterfaces(typeof(IEvents))]
public class MyClass: IEvents
{
public EventOneDelegate OnEventOne;
public void MethodOne(){}
public void MethodTwo(){}
public string PropertyOne{get{} set{}}
}

In Visual Basic, I then create a wrapper class for this MyClass object

cMyClass

option explicit

implements IMethodsAndProperties

public event OnEventOne(byval strSomeValue as string)

private pobjMyClass as MyClass

public sub MethodOne()
pobjMyClass.MethodOne
end sub

public sub MethodTwo()
pobjMyClass.MethodTwo
end sub

public property Get PropertyOne () as string
PropertyOne = pobjMyClass.PropertyOne
end property

public property Let PropertyOne (byval vdata as string)
pobjMyCLass.PropertyOne = vdata
end property

private pobjMyClass_OnEventOne(byval strSomeValue as string)
RaiseEvent OnEventOne(strSomeValue)
end sub
amdrit
2009-10-21 06:09:04 UTC
Permalink
Ever find the answer to your problem once you've shared it with a million
other people? Well I just did, again. The answer is that my event name in
the MyClass and the IEvent interface did not match 100%

In my interface, I labled the event EventOne
In my MyClass, I labled the event OnEventOne

Once I made them match, everything worked automagically again.

Thanks anyway. However, if I am still missing a better methodology, please
let me know.
Post by amdrit
I am looking for the correct way, or most correct way to expose events from
a class object in C# for use by VB6.
I am receiving an error from the VB6 portion at runtime: Object or class
does not support the set of events - Which, according to an MS KB, means
that the event sink is not functioning properly even though at design
time, it all looks correct.
My scenario is based upon a bunch of reading on the web, and still this
solution is not working for me. One thing that troubles me is: Object
brower still doesn't see the interfaces, though the IDE forces me to
implement the whole interface in the class object.
So if anyone cares to point me into the correct direction, I'd be much
obliged. VS C# 2008 / Windows XP sp3, VB6 sp6
[GuidAttribute("GUIDVALUEHERE")]
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
public interface IMethodsAndProperties
{
[DispID(1)]
Void MethodOne();
[DispID(2)]
Void MethodTwo();
[DispID(3)]
String PropertyOne {get;set;}
}
[GuidAttribute("GUIDVALUEHERE")]
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
public interface IEvents
{
[DispID(4)]
Void EventOne(string someValue);
}
public delegate void EventOneDelegate(string someValue);
[GuidAttribute("GUIDVALUEHERE")]
[ClassInterface(ClassInterfaceType.None)]
[ComSourceInterfaces(typeof(IEvents))]
public class MyClass: IEvents
{
public EventOneDelegate OnEventOne;
public void MethodOne(){}
public void MethodTwo(){}
public string PropertyOne{get{} set{}}
}
In Visual Basic, I then create a wrapper class for this MyClass object
cMyClass
option explicit
implements IMethodsAndProperties
public event OnEventOne(byval strSomeValue as string)
private pobjMyClass as MyClass
public sub MethodOne()
pobjMyClass.MethodOne
end sub
public sub MethodTwo()
pobjMyClass.MethodTwo
end sub
public property Get PropertyOne () as string
PropertyOne = pobjMyClass.PropertyOne
end property
public property Let PropertyOne (byval vdata as string)
pobjMyCLass.PropertyOne = vdata
end property
private pobjMyClass_OnEventOne(byval strSomeValue as string)
RaiseEvent OnEventOne(strSomeValue)
end sub
Loading...