怎么用DLL实现两个VB程序间的数据交换
如何用DLL实现两个VB程序间的数据交换?
我做了的DLL,代码如下:
类名:clsTest
Option Explicit
Public Event evTell(ByVal nGun As Integer)
Dim strTest As String
Public Property Get strShow() As String
strShow = strTest
End Property
Public Property Let strShow(ByVal NewValue As String)
strTest = NewValue
End Property
Public Sub Tell(ByVal nGun As Integer)
RaiseEvent evTell(nGun)
strTest = nGun
End Sub
Private Sub Class_Initialize()
strTest = "Start"
End Sub
应用程序1引用了该DLL后,在form1中代码为:
Option Explicit
Dim WithEvents TemN As clsTest
Private Sub Command1_Click() '这是个命令按钮1
TemN.Tell (1)
End Sub
Private Sub Form_Load()
Set TemN = New clsTest
End Sub
Private Sub TemN_evTell(ByVal nGun As Integer)
MsgBox "P1: " & nGun
End Sub
Private Sub Command2_Click() '命令按钮2
TemN.strShow = "Che Show"
End Sub
应用程序2代码:
Option Explicit
Dim WithEvents TemN As clsTest
Private Sub Command1_Click() '应用程序2的按钮
MsgBox TemN.strShow
End Sub
Private Sub Form_Load()
Set TemN = New clsCheInfo
End Sub
Private Sub TemN_evTell(ByVal nGun As Integer)
MsgBox "P2:" & nGun
End Sub
测试时:应用程序1按按钮1后,出现提示“P1:1”,应用程序2无提示
应用程序1按按钮2后,应用程序2按按钮仍然提示是“Start”
我想,这是因为两个应用程序采用了不同的实例的原因,但要实现按应用程序1按钮1后,应用
程序2能得知,及应用程序1修改了strTest的值后,应用程序2能得到这个改变的值,该如何实现呢?
VisualBasic程序开发环境 程序开发 VisualBasic