jpswart82
06-22-2019, 10:26 AM
I'm using Office 2010, and trying to use VBA to access the methods and events of a ActiveX DLL file. The DLL is supplied as part of the SDK of a fingerprint reader from ZKTECO - the reader is connected to the PC via ethernet. My goal is to use the methods and events available in the DLL in order to have a "check in" system where somebody who is registered can come and scan their fngerprint, and then on the excel side their "ID" will link with names from a database. My problem is that I'm struggling to make the event handler get executed when I use the fingerprint reader. I've included the DLL file via Tools -> References, and can view it using the object browser (screenshot below).
24472
The following code in Module1 successfully allows me to connect to the reader and use the methods from the DLL. The class is called CZKEM.
Option Explicit
Public Sub connect()
Dim IPAddress As String
Dim Ports As Long
Dim connected As Boolean
Dim tester As CZKEM
Dim vbool As Variant
Dim i As Integer
Dim success As Boolean
Dim UserID As Long
Dim fingerIndex As Long
Dim machineID As Long
Dim eventMask As Long
Dim iclass As New zkemkeeper.CZKEM
IPAddress = "192.168.1.201"
Ports = 4370
Set tester = New CZKEM
machineID = tester.MachineNumber
UserID = 10
fingerIndex = 0
eventMask = 65535
connected = tester.Connect_NET(IPAddress, Ports)
vbool = tester.RegEvent(machineID, eventMask)
End Sub
I've also managed to get access to the events seen in the object browser using the following code in Class1 Module:
Public WithEvents mApp As zkemkeeper.CZKEM
Public Sub mApp_OnFinger()
Worksheets(1).Range("A1") = "HETHOM"
End Sub
Public Sub mApp_OnKeyPress(ByVal Key As Long)
Worksheets(1).Range("A1") = "HETHOM"
End Sub
Public Sub mApp_onVerify(ByVal UserID As Long)
Worksheets(1).Range("A1") = "HETHOM"
End Sub
However, even though I connect to the reader successfully and run the RegEvent method, which according to the SDK documentation enables real-time events to be triggered, the event handlers never execute. I'm not sure if it is enough that I do the event handler in the Class1 module - I've tried creating an object of Class1, and I can call the event handlers manually, but they don't seem to be triggered when I use the fingerprint reader.
I'm sure there are probably many places where things can go wrong - but I guess my question is mainly if event handlers can be triggered in a class module or if I still have to do something with Class1 in the Module1 code.
24472
The following code in Module1 successfully allows me to connect to the reader and use the methods from the DLL. The class is called CZKEM.
Option Explicit
Public Sub connect()
Dim IPAddress As String
Dim Ports As Long
Dim connected As Boolean
Dim tester As CZKEM
Dim vbool As Variant
Dim i As Integer
Dim success As Boolean
Dim UserID As Long
Dim fingerIndex As Long
Dim machineID As Long
Dim eventMask As Long
Dim iclass As New zkemkeeper.CZKEM
IPAddress = "192.168.1.201"
Ports = 4370
Set tester = New CZKEM
machineID = tester.MachineNumber
UserID = 10
fingerIndex = 0
eventMask = 65535
connected = tester.Connect_NET(IPAddress, Ports)
vbool = tester.RegEvent(machineID, eventMask)
End Sub
I've also managed to get access to the events seen in the object browser using the following code in Class1 Module:
Public WithEvents mApp As zkemkeeper.CZKEM
Public Sub mApp_OnFinger()
Worksheets(1).Range("A1") = "HETHOM"
End Sub
Public Sub mApp_OnKeyPress(ByVal Key As Long)
Worksheets(1).Range("A1") = "HETHOM"
End Sub
Public Sub mApp_onVerify(ByVal UserID As Long)
Worksheets(1).Range("A1") = "HETHOM"
End Sub
However, even though I connect to the reader successfully and run the RegEvent method, which according to the SDK documentation enables real-time events to be triggered, the event handlers never execute. I'm not sure if it is enough that I do the event handler in the Class1 module - I've tried creating an object of Class1, and I can call the event handlers manually, but they don't seem to be triggered when I use the fingerprint reader.
I'm sure there are probably many places where things can go wrong - but I guess my question is mainly if event handlers can be triggered in a class module or if I still have to do something with Class1 in the Module1 code.