Handling events exposed on a .NET class via COM in VB6

Posted by PeanutPower on Stack Overflow See other posts from Stack Overflow or by PeanutPower
Published on 2010-05-04T15:28:24Z Indexed on 2010/05/05 11:08 UTC
Read the original article Hit count: 375

Filed under:
|
|
|

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)

© Stack Overflow or respective owner

Related posts about com

Related posts about .NET