我在使用 AutoIt 的 DLLCall 时遇到问题。
我正在尝试使用 AutoIT 控制 Delcom USB 指示灯 LED 灯。为此,我有一个 .dll,其中包括以下功能:
DelcomGetDeviceCount:返回 Delcom USB 设备的数量
DelcomGetNthDevice:搜索指定设备类型,获取设备名称字符串
DelcomOpenDevice:获取设备名称并返回 USB 设备的句柄
DelcomLEDControl:获取 USB 句柄,设置 LED 状态
这是这些 DLL 函数的文档链接。
我认为我的问题是没有正确格式化指向设备名称的指针,因为我对 DelcomGetNthDevice 的调用返回 0,找不到设备,即使我使用 DelcomGetDeviceCount 检测到一个设备。
我努力了
Local $handleDLL = DLLOpen("C:\DelcomDLL.dll")
Local $stString = DllStructCreate("wchar Name[512]")
Local $devices = DllCall($handleDLL,"dword","DelcomGetDeviceCount","dword",0)
Local $result = DllCall($handleDLL,"dword","DelcomGetNthDevice","dword",1,"dword",0,"ptr",DllStructGetPtr($stString))
Local $handleUSB = DllCall($handleDLL,"handle","DelcomOpenDevice","str",DllStructGetData($stString,"Name"),"dword",0)
Local $result2 = DllCall($handleDLL,"dword","DelcomLEDControl","handle",$handleUSB[0],"dword",0,"dword",1)
MsgBox(0,"# of Devices",$devices[0])
MsgBox(0,"Bool Found Device",$result[0])
DllClose($handleDLL)
和
Local $handleDLL = DLLOpen("C:\Users\b46020\Documents\Asher Project\DelcomDLL.dll")
Local $stString
Local $devices = DllCall($handleDLL,"dword","DelcomGetDeviceCount","dword",0)
Local $result = DllCall($handleDLL,"dword","DelcomGetNthDevice","dword",1,"dword",0,"str*",$stString)
Local $handleUSB = DllCall($handleDLL,"handle","DelcomOpenDevice","str*",$stString,"dword",0)
Local $result2 = DllCall($handleDLL,"dword","DelcomLEDControl","handle",$handleUSB[0],"dword",0,"dword",1)
MsgBox(0,"# of Devices",$devices[0])
MsgBox(0,"Bool Found Device",$result[0])
DllClose($handleDLL)
但在每种情况下,我都会打开 1 个设备,但无法获得其名称。
非常感谢您的帮助。
谢谢,乔纳森