Modify

Opened 3 years ago

Closed 3 years ago

#3833 closed Bug (Fixed)

_WinAPI_RegisterRawInputDevices and $iCount parameter

Reported by: kAnon Owned by: Jpm
Milestone: 3.3.15.5 Component: AutoIt
Version: 3.3.14.5 Severity: None
Keywords: Cc:

Description

The cbSize parameter is calculated incorrectly if $iCount is greater than 1. Multiplication by $ iCount is unnecessary.

#include <WinAPISys.au3>
#include <GUIConstants.au3>
#include <GuiEdit.au3>

Global $g_idEdit
test()

Func test()
    Local $tRAWINPUTDEVICEs = DllStructCreate('struct;ushort UsagePage1;ushort Usage1;dword Flags1;hwnd hTarget1;endstruct;' & _
            'struct;ushort UsagePage2;ushort Usage2;dword Flags2;hwnd hTarget2;endstruct')
    DllStructSetData($tRAWINPUTDEVICEs, 'UsagePage1', 0x01)
    DllStructSetData($tRAWINPUTDEVICEs, 'Usage1', 0x02)
    DllStructSetData($tRAWINPUTDEVICEs, 'Flags1', $RIDEV_INPUTSINK)
    DllStructSetData($tRAWINPUTDEVICEs, 'hTarget1', GUICreate(''))
    DllStructSetData($tRAWINPUTDEVICEs, 'UsagePage2', 0x01)
    DllStructSetData($tRAWINPUTDEVICEs, 'Usage2', 0x06)
    DllStructSetData($tRAWINPUTDEVICEs, 'Flags2', $RIDEV_INPUTSINK)
    DllStructSetData($tRAWINPUTDEVICEs, 'hTarget2', GUICreate(''))

    ConsoleWrite('_WinAPI_RegisterRawInputDevices: ' & _WinAPI_RegisterRawInputDevices($tRAWINPUTDEVICEs, 2) & @CRLF)  ; error
    _WinAPI_RegisterRawInputDevicesFixed($tRAWINPUTDEVICEs, 2) ; work

    GUICreate('', 400, 400, -1, -1, -1, $WS_EX_TOPMOST)
    $g_idEdit = GUICtrlCreateEdit('', 10, 10, 380, 380)
    GUIRegisterMsg($WM_INPUT, WM_INPUT)
    GUISetState()

    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
EndFunc   ;==>test

Func WM_INPUT($hGui, $iMsg, $wParam, $lParam)
    #forceref $hGui, $iMsg, $wParam, $lParam
    Local $tRAWINPUTHEADER = DllStructCreate($tagRAWINPUTHEADER)
    _WinAPI_GetRawInputData($lParam, $tRAWINPUTHEADER, DllStructGetSize($tRAWINPUTHEADER), $RID_HEADER)
    Switch DllStructGetData($tRAWINPUTHEADER, 'Type')
        Case $RIM_TYPEMOUSE
            Local $tRAWINPUTMOUSE = DllStructCreate($tagRAWINPUTMOUSE)
            _WinAPI_GetRawInputData($lParam, $tRAWINPUTMOUSE, DllStructGetSize($tRAWINPUTMOUSE), $RID_INPUT)
            If DllStructGetData($tRAWINPUTMOUSE, 'ButtonFlags') Then _GUICtrlEdit_AppendText($g_idEdit, 'RIM_TYPEMOUSE' & @CRLF)
        Case $RIM_TYPEKEYBOARD
            _GUICtrlEdit_AppendText($g_idEdit, 'RIM_TYPEKEYBOARD' & @CRLF)
    EndSwitch
EndFunc   ;==>WM_INPUT

Func _WinAPI_RegisterRawInputDevicesFixed($paDevice, $iCount = 1)
    Local $aRet = DllCall('user32.dll', 'bool', 'RegisterRawInputDevices', 'struct*', $paDevice, 'uint', $iCount, _
            'uint', DllStructGetSize(DllStructCreate($tagRAWINPUTDEVICE)))
    If @error Or Not $aRet[0] Then Return SetError(@error, @extended, 0)

    Return $aRet[0]
EndFunc   ;==>_WinAPI_RegisterRawInputDevicesFixed

Windows 10 Pro 21H1 x64
AutoIt Version: 3.3.14.5 / 3.3.15.4

Attachments (0)

Change History (1)

comment:1 Changed 3 years ago by Jpm

  • Milestone set to 3.3.15.5
  • Owner set to Jpm
  • Resolution set to Fixed
  • Status changed from new to closed

Fixed by revision [12581] in version: 3.3.15.5

Guidelines for posting comments:

  • You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
  • In-depth discussions should take place on the forum.

For more information see the full version of the ticket guidelines here.

Add Comment

Modify Ticket

Action
as closed The owner will remain Jpm.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.