Handling events exposed on a .NET class via COM in VB6
My test .NET (class libary registered for interop in compiler settings) code:
Imports System.Runtime.InteropServices
<InterfaceType(ComInterfaceType.InterfaceIsIDispatch), ComVisible(True)> _
Public Interface MyEventInterface
<DispId(1)> Event Exploded(ByVal Text As String)
<DispId(2)> Sub PushRedButton()
End Interface
<ClassInterface(ClassInterfaceType.None)> _
Public Class EventTest
Implements MyEventInterface
Public Event Exploded(ByVal Text As String) Implements MyEventInterface.Exploded
Public Sub PushRedButton() Implements MyEventInterface.PushRedButton
RaiseEvent Exploded("Bang")
End Sub
End Class
My test VB6 application winforms code (which references the above class libary):
Public ct As New ComTest1.EventTest
Private Sub Command1_Click()
ct.add_Exploded (ExplodedHandler)
ct.PushRedButton
ct.remove_Exploded (ExplodedHandler)
End Sub
Private Sub ExplodedHandler(ByVal Text As String)
MsgBox Text
End Sub
Specifially I'm not sure how to set up the handler in VB6 the compile error I get is "Argument not optional" on this line in the VB6:
ct.add_Exploded (ExplodedHandler)