VB6.0回调函数求助

CCC的 CCC的 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
'public.bas
Option Explicit

Public hPort As Long
Public clock_id As Long
Public started As Boolean
Public callback1 As Long
Public callback2 As Long
Public callback3 As Long
Public serialnum As String
Public mydevid As Integer
Public myip As String
Public myclockid As Integer
Public myclock As Integer
Public myport As Integer
Public mystate As String
Public myrecords As String

Public Sub FunOnDeviceLogin(ByVal Dev_id As Integer, ByVal serial As Long, ByVal ip As Long, ByVal port As Integer, ByRef Heartbeat As Integer)

'回调函数1
Dim hasDevice As Boolean
Dim i As Integer

hasDevice = False
If serialnum = SysAllocString(serial) Then
hasDevice = True
mydevid = Dev_id
myip = SysAllocString(ip)
myport = port
End If

If hasDevice = False Then
myclockid = Dev_id
serialnum = SysAllocString(serial)
myip = SysAllocString(ip)
myport = port
mystate = "登录"
End If

Heartbeat = 2
End Sub

Public Sub FunOnRefreshDeviceStateBySerial(ByVal Dev_id As Integer, ByVal serial As Long, ByVal state As Integer, ByVal RecordCount As Integer)
'回调函数2
Dim a As String
If serialnum = SysAllocString(serial) Then
If state = 0 Then
mystate = "状态:脱机"
Else
mystate = "状态:联机"
End If
End If
End Sub

Public Sub FunOnRecieveBatchRecordBySerialStr(ByVal Dev_id As Integer, ByVal serial As Long, ByVal index As Integer, ByVal RecordCount As Integer, ByVal Records As Long, ByRef bReturnOK As Boolean)
'回调函数3
myrecords = SysAllocString(Records)
bReturnOK = True
End Sub

'delphi中的声明
'procedure SetUpLoadProcStr(vOnDeviceLogin:FunOnDeviceLogin; vOnRefreshDeviceState: FunOnRefreshDeviceStateBySerial; vOnRecieveBatchRecord: FunOnRecieveBatchRecordBySerialStr); stdcall;

Public Declare Sub SetUpLoadProcStr Lib "EastRiver.Dll" (ByVal FunOnDeviceLogin As Long, ByVal FunOnRefreshDeviceStateBySerial As Long, ByVal FunOnRecieveBatchRecordBySerialStr As Long)

'delphi中的声明
'function StartUpLoad(vListenPort:Integer):boolean; stdcall; external 'EastRiver.dll';
Public Declare Function StartUpLoad Lib "EastRiver.Dll" (ByVal port As Long) As Boolean

Declare Function SysAllocString Lib "oleaut32.dll" (ByVal pOlechar As Long) As String


调用

Function GetFuncPtr(ByVal Ptr As Long) As Long
GetFuncPtr = Ptr
End Function

Private Sub Command4_Click()
Dim iPort As Integer

callback1 = GetFuncPtr(AddressOf FunOnDeviceLogin)
callback2 = GetFuncPtr(AddressOf FunOnRefreshDeviceStateBySerial)
callback3 = GetFuncPtr(AddressOf FunOnRecieveBatchRecordBySerialStr)

iPort = CInt(Text1.Text)
started = StartUpLoad(iPort)
If started Then
Command5.Enabled = 1
Command4.Enabled = 0
Call SetUpLoadProcStr(VarPtr(callback1), VarPtr(callback2), VarPtr(callback3))
End If
End Sub
...全文

相关推荐

评论 6
收藏 已收藏
分享
返回顶部
CCC的
API 1,488 成员 23,270 内容