Search in sources :

Example 1 with RAWINPUTDEVICELIST

use of com.sun.jna.platform.win32.WinUser.RAWINPUTDEVICELIST in project jna by java-native-access.

the class User32Util method GetRawInputDeviceList.

public static final List<RAWINPUTDEVICELIST> GetRawInputDeviceList() {
    IntByReference puiNumDevices = new IntByReference(0);
    RAWINPUTDEVICELIST placeholder = new RAWINPUTDEVICELIST();
    int cbSize = placeholder.sizeof();
    // first call is with NULL so we query the expected number of devices
    int returnValue = User32.INSTANCE.GetRawInputDeviceList(null, puiNumDevices, cbSize);
    if (returnValue != 0) {
        throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
    }
    int deviceCount = puiNumDevices.getValue();
    RAWINPUTDEVICELIST[] records = (RAWINPUTDEVICELIST[]) placeholder.toArray(deviceCount);
    returnValue = User32.INSTANCE.GetRawInputDeviceList(records, puiNumDevices, cbSize);
    if (returnValue == (-1)) {
        throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
    }
    if (returnValue != records.length) {
        throw new IllegalStateException("Mismatched allocated (" + records.length + ") vs. received devices count (" + returnValue + ")");
    }
    return Arrays.asList(records);
}
Also used : IntByReference(com.sun.jna.ptr.IntByReference) RAWINPUTDEVICELIST(com.sun.jna.platform.win32.WinUser.RAWINPUTDEVICELIST)

Aggregations

RAWINPUTDEVICELIST (com.sun.jna.platform.win32.WinUser.RAWINPUTDEVICELIST)1 IntByReference (com.sun.jna.ptr.IntByReference)1