GetRawInputDeviceList function (winuser.h)

Enumerates the raw input devices attached to the system.

Syntax

UINT GetRawInputDeviceList(
  [out, optional] PRAWINPUTDEVICELIST pRawInputDeviceList,
  [in, out]       PUINT               puiNumDevices,
  [in]            UINT                cbSize
);

Parameters

[out, optional] 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.

[in, out] 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. If this value is greater than or equal to the number of devices attached to the system, then the value is unchanged, and the number of devices is reported as the return value.

[in] 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 = NULL;
while (true) {
    if (GetRawInputDeviceList(NULL, &nDevices, sizeof(RAWINPUTDEVICELIST)) != 0) { Error();}
    if (nDevices == 0) { break; }
    if ((pRawInputDeviceList = malloc(sizeof(RAWINPUTDEVICELIST) * nDevices)) == NULL) {Error();}
    nDevices = GetRawInputDeviceList(pRawInputDeviceList, &nDevices, sizeof(RAWINPUTDEVICELIST));
    if (nDevices == (UINT)-1) {
        if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) { Error(); }
        // Devices were added.
        free(pRawInputDeviceList);
        continue;
    }
    break;
}
// do the job...
// after the job, free the RAWINPUTDEVICELIST
free(pRawInputDeviceList);

Requirements

Requirement Value
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
API set ext-ms-win-ntuser-rawinput-l1-1-0 (introduced in Windows 10, version 10.0.14393)

See also

Conceptual

GetRawInputDeviceInfo

RAWINPUTDEVICELIST

Raw Input

Reference