处理事件通过COM在VB6暴露在.NET类处理事件
我的测试.NET(类libary在编译器设置注册的互操作)代码:
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
我的测试VB6应用程序的WinForms代码(引用上面的类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我不知道如何设置处理程序在VB6编译错误我得到的是“参数不选择有理”在这条线在VB6:
ct.add_Exploded (ExplodedHandler)
哪里是你的add_Exploded声明? – volody 2010-05-04 16:04:52
COM属性创建它。即在VB6中,由于我相信Idispatch接口,intellisense add_和remove_是否存在? – PeanutPower 2010-05-05 08:56:58