'DLL内cTest内代码
Option Explicit
'动态使用具有事件的对象
'
'BY 嗷嗷叫的老马
'http://www.m5home.com
Public Event KK()
Public Function getEvent()
RaiseEvent KK
End Function
程序代码
'EXE内代码.需要两个CommandButton.
Option Explicit
'动态使用具有事件的对象
'
'BY 嗷嗷叫的老马
'http://www.m5home.com
Private Declare Sub Sleep Lib "kernel32.dll" ( _
ByVal dwMilliseconds As Long)
Dim WithEvents A As cTest
Private Sub Form_Load()
On Error Resume Next
Set A = CreateObject("pTest.cTest")
If A Is Nothing Then
MsgBox "对象初始化失败!", vbOKOnly Or vbInformation
End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
Set A = Nothing
End Sub
Private Sub Command1_Click()
Call A.getEvent
End Sub
Private Sub Command2_Click()
Shell "regsvr32 pTest.dll"
Sleep 1000
Call Form_Load
End Sub
Private Sub A_KK()
MsgBox "事件触发测试!", vbOKOnly Or vbInformation
End Sub
★VB部分相关文章推荐:★
☆关于VB中Shell及ShellExecute的总结与记录
☆[vb]On Error GoTo 0和On Error resume区别
☆VB抓图