#3833 closed Bug (Fixed)

_WinAPI_RegisterRawInputDevices and $iCount parameter

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


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

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)

    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)
            _GUICtrlEdit_AppendText($g_idEdit, 'RIM_TYPEKEYBOARD' & @CRLF)
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: /

Attachments (0)

Change History (1)

comment:1 Changed 15 months ago by Jpm

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

Fixed by revision [12581] in version:

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

as closed The owner will remain Jpm.

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

Note: See TracTickets for help on using tickets.