1
我遇到了AutoIt的DLLCall問題。AutoIt DllCall到USB
我想用AutoIT控制Delcom USB指示燈LED燈。要做到這一點,我有一個.dll,其中包括以下功能:
DelcomGetDeviceCount:返回DELCOM USB設備的數量
DelcomGetNthDevice:對指定的設備類型的搜索,獲取設備名稱的字符串
DelcomOpenDevice :需要設備名稱,並返回處理到USB設備
DelcomLEDControl:採用USB手柄,設置的LED
狀態這裏是a link到問題解決的文這些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個設備,但無法得到它的名字。
我將不勝感激您的幫助。
感謝, 喬納森
兩件事情出現錯誤的第一個例子,你混合WCHAR []和STR,這是非常不同的(儘管AutoIt的應該做的在這種情況下轉換爲你)。我需要一個指向頭文件的鏈接來檢查它,但是它看起來像是在傳遞一個指向字符串的指針,而不是指向字符串的指針數組。我很快寫了我認爲應該能夠給你所有設備的名稱,但我當然不能測試它:https://gist.github.com/MattDiesel/5862545 – Matt
是的,謝謝馬特,我改變了設備名稱以char []和它的工作。 – MrInvertible
很高興看到你得到它的工作。 – Matt