Subscribe to C # .net Event in VB6

I need to be able to handle the .net event in VB6. So far I have created it, making me a visible C # class. My VB6 object can call methods on it perfectly, but now I need a way to communicate with .net on VB. If I add an event to my C # class, then the .net shell seems to add add_EventName and remove_EventName, which I assume is to subscribe and unsubscribe to the event. But I'm still a newbie when it comes to VB6, and I came, so I'm not sure how to use it.

It seems that add_EventName is receiving an EventNameEventHadler event, but what am I giving it? I tried sub, but this gives me a runtime error. Does anyone know how to use this? Here is an example of what I have

Private oHost As HostService.IHost

Private Sub Form_Load()
    Set oHost = New HostService.Host
    oHost.Start
    oHost.add_EvalReceived EvalReceivedEventHandler
End Sub

Private Sub EvalReceivedEventHandler(ByVal sender As Variant, ByVal e As EvalReceivedEventArgs)
MsgBox "Eval Received in VB: " & e.Eval.TimeSent & ":" & e.Eval.FirstName & " " & e.Eval.LastName & " - " & e.Eval.Comments
End Sub

So the oHost.add_EvalReceived line is incorrect

+5
3

WithEvents oHost

Private WithEvents oHost As HostService.IHost

IDE oHost. Form_Load. oHost.

: COM-. .Net interop, , .

+4

, MarkJ. , COM. , :

[ComSourceInterfaces(typeof(IHostEvents))]
[ClassInterface(ClassInterfaceType.None)]
[Guid("037CF765-4C30-4CF7-969C-1775E79844CE")]
public class Host : IHost
{
    //IHost implementation
}

[ComVisible(true)]
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
[Guid("8C0C3F0E-5793-4E11-AB20-3A556C0B6790")]
public interface IHostEvents
{
    [DispId(1)]
    void EvalReceived(object sender, EvalReceivedEventArgs e);
}
+4

In VB6, you can use the operator AddressOfto create a delegate implicitly:

oHost.add_EvalReceived AddressOf EvalReceivedEventHandler
+1
source

All Articles