Such errors are thrown when one of the parameters does not pass the internal checks of Windows API functions. In most cases - besides an invalid handle which has the
ERROR_INVALID_HANDLE
code and passing NULL pointers which is obvious - a member of a passed structure is not properly set.
Read the documentation of the function. When passing structures - respectively pointers to structures - it is often required to clear members and initialise a size member if present. The latter is the case here:
pData [in, out, optional]
Type: LPVOID
A pointer to a buffer that contains the information specified by uiCommand. If uiCommand is RIDI_DEVICEINFO, set the cbSize member of RID_DEVICE_INFO to sizeof(RID_DEVICE_INFO) before calling GetRawInputDeviceInfo.
So use something like
RID_DEVICE_INFO device_info = {};
UINT info_size = device_info.cbSize = sizeof(device_info);
int result = GetRawInputDeviceInfo(device_iterator->hDevice, RIDI_DEVICEINFO, &device_info, &info_size);
[EDIT]
You have not shown the full relation between getting the device handle and calling
GetPointerDeviceRects()
.
But all your calls to
GetRawInputDeviceInfo()
are failing with error
ERROR_INVALID_PARAMETER
so that your
deviceHandle
variable is never set / changed.
Besides passing an improperly initialised structure, you made another mistake:
You did not handled the error properly when it occurred. The value returned by
GetLastError()
is never cleared but only set when an API function fails. So you have to call it only when an API function indicates failure by the return value. And it has to be called before calling any other API function (which usually means: any other function because those may also call API functions).
[/EDIT]