處理事件通過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