GetRawInputDeviceList function

Enumerates the raw input devices attached to the system.

Syntax

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

Parameters

pRawInputDeviceList

Type: PRAWINPUTDEVICELIST

An array of RAWINPUTDEVICELIST structures for the devices attached to the system. If NULL, the number of devices are returned in *puiNumDevices.

puiNumDevices

Type: PUINT

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

Type: UINT

The size of a RAWINPUTDEVICELIST structure, in bytes.

Return Value

Type: UINT

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.

Examples

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);

Requirements

   
Minimum supported client Windows XP [desktop apps only]
Minimum supported server Windows Server 2003 [desktop apps only]
Target Platform Windows
Header winuser.h (include Windows.h)
Library User32.lib
DLL User32.dll

See Also

Conceptual

GetRawInputDeviceInfo

RAWINPUTDEVICELIST

Raw Input

Reference