Hi i have a vb6 interface called CLSFW_SBSession with an event:
Public Event DataTransfer(ByVal Data As Variant)
Public Property Get ActionID() As Long
End Property
...
I need to extend it with a c# interop class. I tried with:
[ComVisible(true)]
[Guid("ddb976bd-fe29-44d5-a163-e7780a4bb897")]
public class ClsSbSession : FWBO_LibSrv.CLSFW_SBSession
public event __CLSFW_SBSession_DataTransferEventHandler DataTransfer;
...
Now if i declare a object of this type in vb6 and i instance it, without With events, it works:
Private session As FWBO_LibSrv.CLSFW_SBSession
Set session = new ClsSbSession()
But if i use:
Private WithEvents session As FWBO_LibSrv.CLSFW_SBSession
and i try to instance it:
Set session = new ClsSbSession()
I receive an error:
Object or class does not support the set of events
How can i do for manage events from vb6 of my c# class? thanks
This is pretty murky, VB6 does not permit declaring an interface. It does generate them from a VB6 Class declaration, their name start with an underscore. There should be two, one for the class and probably named
_CLSFW_SBSession
, another for the event. One way to find these interface names is by running Oleview.exe from the Visual Studio Command Prompt. Use File + View Typelib and select the VB6 executable. Find the coclass declaration and note the interfaces marked by the [default] and [source] attributes.You need to derive your class from the [default] interface. And you must use the [ComSourceInterfaces] attribute to name the [source] interface. The MSDN howto page is here. It isn't otherwise clear why you are trying to mimic the VB6 class, that is only necessary if you need a drop-in replacement for the existing VB6 class and need to keep legacy client programs running. That has additional requirements, like matching the guids.