GetRawInputDeviceList Function

The GetRawInputDeviceList function enumerates the raw input devices attached to the system.

Syntax

UINT GetRawInputDeviceList(      
    PRAWINPUTDEVICELIST pRawInputDeviceList,     PUINT puiNumDevices,     UINT cbSize );

Parameters

pRawInputDeviceList
[out] Pointer to buffer that holds an array of RAWINPUTDEVICELIST structures for the devices attached to the system. If NULL, the number of devices are returned in *puiNumDevices.
puiNumDevices
[in, out] Pointer to a variable. If pRawInputDeviceList is NULL, the function populates this variable with the number of devices attached to the system; otherwise, this variable specifies the number of RAWINPUTDEVICELIST structures that can be contained in the buffer to which pRawInputDeviceList points. If this value is less than the number of devices attached to the system, the function returns the actual number of devices in this variable and fails with ERROR_INSUFFICIENT_BUFFER.
cbSize
[in] Size of a RAWINPUTDEVICELIST structure.

Return Value

If the function is successful, the return value is the number of devices stored in the buffer pointed to by pRawInputDeviceList.

On any other error, the function returns (UINT) -1 and GetLastError returns the error indication.

Remarks

The devices returned from this function are the mouse, the keyboard, and other Human Interface Device (HID) devices.

To get more detailed information about the attached devices, call GetRawInputDeviceInfo using the hDevice from RAWINPUTDEVICELIST. The following sample code shows a typical call to GetRawInputDeviceList:

UINT nDevices;
PRAWINPUTDEVICELIST pRawInputDeviceList;
if (GetRawInputDeviceList(NULL, &nDevices, sizeof(RAWINPUTDEVICELIST)) != 0) { Error();}
if ((pRawInputDeviceList = malloc(sizeof(RAWINPUTDEVICELIST) * nDevices)) == NULL) {Error();}
if (GetRawInputDeviceList(pRawInputDeviceList, &nDevices, sizeof(RAWINPUTDEVICELIST)) == (<dtype rid="UINT"/>)-1) {Error();}
// do the job...

// after the job, free the RAWINPUTDEVICELIST
free(pRawInputDeviceList);

Function Information

Minimum DLL Versionuser32.dll
HeaderDeclared in Winuser.h, include Windows.h
Import libraryUser32.lib
Minimum operating systems Windows XP

See Also

Tags :


Community Content

Đonny
Visual Basic 9 Declaration & Usage
Public Declare Auto Function GetRawInputDeviceList Lib "user32.dll" ( _
<MarshalAs(UnmanagedType.LPArray, SizeParamIndex:=1, ArraySubType:=UnmanagedType.Struct), [In](), Out()> ByVal pRawInputDeviceList As RAWINPUTDEVICELIST(), _
<[In](), Out()> ByRef puiNumDevices As Int32, _
<[In]()> ByVal cbSize As Int32) As Int32

Due to marshalling limitations this function must be called twice to obtain list of devices.

  

Dim List As RAWINPUTDEVICELIST()
Dim Number% = 0
Dim Ret = GetRawInputDeviceList(Nothing, Number, RAWINPUTDEVICELIST.Size)
If Ret = -1 Then
'Error
Exit Sub
End If
ReDim List(Number - 1)
Ret = GetRawInputDeviceList(List, Number, RAWINPUTDEVICELIST.Size)
If Ret = -1 Then
'Error
Exit Sub
End If

'Do something with items in the List array



ChGu
C# PInvoke
[DllImport("user32.dll")]
extern uint GetRawInputDeviceList(IntPtr pRawInputDeviceList,
ref uint puiNumDevices,
uint cbSize);
Tags : c# pinvoke

Page view tracker