Programmatically Unsubscribe from an Event

I have a vb6 application that uses a COM object (C # COM object). A vb6 application subscribes to an event posted by a COM object (C #).

My problem is that I do not know how to programmatically unsubscribe from this event. The only way I know how to write is not by subscribing to first place (e.g. commenting out an event handler in vb6 code).

Is there a way to do this unsubscribing at runtime (programmatically)? Maybe something needs to be done on the C # side by specifying a delegate that matches the vb6 event handler and doesn't call it?

Thanks in advance.

+5
source share
2 answers

VB6, : WithEvents . , , , , Nothing. , / , .

Dim MyObject As MyClass
Dim WithEvents MyObjectEvents As MyClass

Public Sub MyObjectEvents_EventName()
  MsgBox "Received event"
End Sub

Private Sub Subscribe()
  Set MyObjectEvents = MyObject
End Sub

Private Sub Unsubscribe()
  Set MyObjectEvents = Nothing
End Sub
+2

, , .

.NET EventXYZ. VB6- ( ) .NET-, .

This is essentially the same method as COM and .NET events using internall, but .NET has more granularity to the event level.

+2
source

All Articles