SocramMalaquias Posted August 28, 2009 Share Posted August 28, 2009 (edited) Hi. I'm a newbie using DLL. I have the following code: Opt("MustDeclareVars", 1) Dim $dev, $strDev, $strData, $strRead, $hand, $read $dev = RegEnumKey("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\HID\Vid_0813&Pid_1006", 1) If @error Then MsgBox(16, "Error", "No se ha detectado el dispositivo DACS.") ;~ In spanish: "DACS do not detected" Exit EndIf ConsoleWrite("Bus: " & $dev & @LF) RegEnumKey("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\HID\Vid_0813&Pid_1006", 2) If Not @error Then MsgBox(16, "Error", "Hay más de un dispositivo DACS conectado. Sólo se usará uno de ellos.") ;~ In spanish: "There are more than one DACS connected. Only one will be used" EndIf $dev = "\\?\HID#Vid_0813&Pid_1006#" & $dev & "#{4d1e55b2-f16f-11cf-88cb-001111000030}" ConsoleWrite("Device Path: " & $dev & @LF) $strDev = DllStructCreate("char[" & StringLen($dev) & "]") $strData = DllStructCreate("byte[32]") DllStructSetData($strDev, 1, $dev) $hand = DllCall("kernel32.dll", "hwnd", "CreateFile", "ptr", DllStructGetPtr($strDev), "int", 0xC0000000, "int", 0x3, "ptr", 0, "int", 0x3, "int", 0x80, "int", 0) DllCall("kernel32.dll", "int", "ReadFile", "hwnd", $hand, "ptr*", DllStructGetPtr($strData), "int", 32, "long_ptr", 0, "int", 0) ConsoleWrite(DllStructGetData($strData, 1)) I'm trying to read data from a HID with VID 0x0813 and PID 0x1006 in the simplest way possible. This program doesn't gives any errors, so I can't understand where is the problem T.T Also, the device isn't used by another process Any help? Thanks! Edited August 28, 2009 by SocramMalaquias Link to comment Share on other sites More sharing options...
Zedna Posted August 28, 2009 Share Posted August 28, 2009 Look here at example for _WinAPI_ReadFile() from standard UDFs http://www.autoitscript.com/forum/index.php?showtopic=76829 Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
wolf9228 Posted August 28, 2009 Share Posted August 28, 2009 Hi. I'm a newbie using DLL. I have the following code: Opt("MustDeclareVars", 1) Dim $dev, $strDev, $strData, $strRead, $hand, $read $dev = RegEnumKey("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\HID\Vid_0813&Pid_1006", 1) If @error Then MsgBox(16, "Error", "No se ha detectado el dispositivo DACS.") ;~ In spanish: "DACS do not detected" Exit EndIf ConsoleWrite("Bus: " & $dev & @LF) RegEnumKey("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\HID\Vid_0813&Pid_1006", 2) If Not @error Then MsgBox(16, "Error", "Hay más de un dispositivo DACS conectado. Sólo se usará uno de ellos.") ;~ In spanish: "There are more than one DACS connected. Only one will be used" EndIf $dev = "\\?\HID#Vid_0813&Pid_1006#" & $dev & "#{4d1e55b2-f16f-11cf-88cb-001111000030}" ConsoleWrite("Device Path: " & $dev & @LF) $strDev = DllStructCreate("char[" & StringLen($dev) & "]") $strData = DllStructCreate("byte[32]") DllStructSetData($strDev, 1, $dev) $hand = DllCall("kernel32.dll", "hwnd", "CreateFile", "ptr", DllStructGetPtr($strDev), "int", 0xC0000000, "int", 0x3, "ptr", 0, "int", 0x3, "int", 0x80, "int", 0) DllCall("kernel32.dll", "int", "ReadFile", "hwnd", $hand, "ptr*", DllStructGetPtr($strData), "int", 32, "long_ptr", 0, "int", 0) ConsoleWrite(DllStructGetData($strData, 1)) I'm trying to read data from a HID with VID 0x0813 and PID 0x1006 in the simplest way possible. This program doesn't gives any errors, so I can't understand where is the problem T.T Also, the device isn't used by another process Any help? Thanks! About DllCall CreateFile Function http://msdn.microsoft.com/en-us/library/aa363858%28VS.85%29.aspx ReadFile Function http://msdn.microsoft.com/en-us/library/aa365467%28VS.85%29.aspx CloseHandle Function http://msdn.microsoft.com/en-us/library/ms724211%28VS.85%29.aspx expandcollapse popup#Include <Array.au3> Const $GENERIC_READ = (0x80000000) Const $GENERIC_WRITE = (0x40000000) Const $GENERIC_EXECUTE = (0x20000000) Const $GENERIC_ALL = (0x10000000) Const $NULL = 0 Const $FILE_SHARE_READ = 0x00000001 Const $FILE_SHARE_WRITE = 0x00000002 Const $FILE_SHARE_DELETE = 0x00000004 Const $CREATE_NEW = 1 Const $CREATE_ALWAYS = 2 Const $OPEN_EXISTING = 3 Const $OPEN_ALWAYS = 4 Const $TRUNCATE_EXISTING = 5 Const $FILE_ATTRIBUTE_READONLY = 0x00000001 Const $FILE_ATTRIBUTE_HIDDEN = 0x00000002 Const $FILE_ATTRIBUTE_SYSTEM = 0x00000004 Const $FILE_ATTRIBUTE_DIRECTORY = 0x00000010 Const $FILE_ATTRIBUTE_ARCHIVE = 0x00000020 Const $FILE_ATTRIBUTE_ENCRYPTED = 0x00000040 Const $FILE_ATTRIBUTE_NORMAL = 0x00000080 Const $FILE_ATTRIBUTE_TEMPORARY = 0x00000100 Const $FILE_FLAG_WRITE_THROUGH = 0x80000000 Const $FILE_FLAG_OVERLAPPED = 0x40000000 Const $FILE_FLAG_NO_BUFFERING = 0x20000000 Const $FILE_FLAG_RANDOM_ACCESS = 0x10000000 Const $FILE_FLAG_SEQUENTIAL_SCAN = 0x08000000 Const $FILE_FLAG_DELETE_ON_CLOSE = 0x04000000 Const $FILE_FLAG_BACKUP_SEMANTICS = 0x02000000 Const $FILE_FLAG_POSIX_SEMANTICS = 0x01000000 Const $FILE_FLAG_OPEN_REPARSE_POINT = 0x00200000 Const $FILE_FLAG_OPEN_NO_RECALL = 0x00100000 Const $SECURITY_CONTEXT_TRACKING = 0x00040000 Const $SECURITY_EFFECTIVE_ONLY = 0x00080000 Const $SECURITY_SQOS_PRESENT = 0x00100000 Const $SECURITY_VALID_SQOS_FLAGS = 0x001F0000 $ISize = FileGetSize ( "image.jpg" ) + 1 $HANDLE = WINAPI_CreateFile("image.jpg") if ($HANDLE) Then MsgBox(0,"MSG","File Create") $tBuffer = DllStructCreate("byte[" & $ISize & "]") $PBuffer = DllStructGetPtr($tBuffer) if WINAPI_ReadFile($HANDLE,$PBuffer,DllStructGetSize($tBuffer) ) Then MsgBox(0,"MSG","File Read") if WINAPI_CloseHandle($HANDLE) Then MsgBox(0,"MSG","File Close") $FileOpen = FileOpen("image2.jpg",2) FileWrite($FileOpen,DllStructGetData($tBuffer,1)) FileClose($FileOpen) Func WINAPI_CreateFile( _ $lpFileName, _ $dwCreationDisposition = $OPEN_ALWAYS, _ $dwDesiredAccess = $GENERIC_ALL , _ $dwShareMode = $NULL , _ $dwFlagsAndAttributes = $NULL) $HANDLE = DllCall("Kernel32.dll","hwnd","CreateFile","str",$lpFileName,"long",$dwDesiredAccess, _ "long",$dwShareMode,"ptr",0,"long",$dwCreationDisposition,"long",$dwFlagsAndAttributes,"hwnd",0) if @error Then Return SetError(@error,0,0) if $HANDLE[0] And Not ($HANDLE[0] = 0xFFFFFFFF) Then Return SetError(@error,0,$HANDLE[0]) Return SetError(@error,0,0) EndFunc Func WINAPI_ReadFile( _ $hFile, _ $lpBuffer, _ $nNumberOfBytesToRead) $BOOL = DllCall("Kernel32.dll","int","ReadFile","hwnd",$hFile,"ptr",$lpBuffer,"long",$nNumberOfBytesToRead _ ,"ptr*",0,"ptr",0) if @error Then Return SetError(@error,0,0) Return SetError(@error,0,$BOOL[0]) EndFunc Func WINAPI_CloseHandle( _ $hObject) $BOOL = DllCall("Kernel32.dll","int","CloseHandle","hwnd",$hObject) if @error Then Return SetError(@error,0,0) Return SetError(@error,0,$BOOL[0]) EndFunc صرح السماء كان هنا Link to comment Share on other sites More sharing options...
SocramMalaquias Posted August 29, 2009 Author Share Posted August 29, 2009 THANKS!!!! THANK YOU VERY MUCH!!! Link to comment Share on other sites More sharing options...
SocramMalaquias Posted August 30, 2009 Author Share Posted August 30, 2009 Here is my finished code: http://s4x8.webatu.com/?seccion=dacs2mouse The web is in Spanish, but in the left bar you have got a Google Translator gadget See you son Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now