我在使用AutoIt的DLLCall时遇到了麻烦。
我正在尝试控制一个德尔康USB指示灯LED灯使用AutoIT。为此,我有一个.dll,它包含以下函数:
DelcomGetDeviceCount:返回Delcom USB设备数量
DelcomGetNthDevice:搜索指定的设备类型,获取设备名称字符串
USB :获取设备名称并返回DelcomOpenDevice设备的句柄
DelcomLEDControl:获取USB手柄,设置发光二极管的状态
以下是有关这些DLL函数的文档的a link。
我认为我的问题是没有正确地格式化指向设备名称的指针,因为即使我检测到一个使用DelcomGetDeviceCount的设备,我对DelcomGetNthDevice的调用也会返回0,即找不到设备。
我试过了
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)但在每种情况下,我都打开了一个设备,但无法获得其名称。
我将非常感谢你的帮助。
谢谢,乔纳森
发布于 2013-06-27 00:26:07
解决了它:
Local $handleDLL = DllOpen("C:\DelcomDLL.dll")
$strName = DllStructCreate("char Name[512]")
$ptrName = DllStructGetPtr($strName)
Local $result = DllCall($handleDLL, "dword", "DelcomGetNthDevice", "dword", 0, "dword", 0, "ptr", $ptrName)
Local $handleUSB = DllCall($handleDLL, "handle", "DelcomOpenDevice", "str", DllStructGetData($strName, "Name"), "dword", 0)
Local $result2 = DllCall($handleDLL, "dword", "DelcomLEDControl", "handle", $handleUSB[0], "dword", $color, "dword", $state)
Local $closed = DllCall($handleDLL,"dword","DelcomCloseDevice","handle",$handleUSB[0])
DllClose($handleDLL)https://stackoverflow.com/questions/17303202
复制相似问题