Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to call the GetPointerDeviceRects api in c++, to get the range of the touch digitizer. It requires 3 parameters. One is the handle. I was able to get the correct handle to the device using GetRawInputDeviceList. As for the other parameters, I have declared them as shown in the code extract below. I am getting the error code 87 which means Invalid Parameter. Could you please help me resolve this error.

What I have tried:

<pre>RECT   pointerDeviceRect;
RECT   displayRect;
GetPointerDeviceRects(device, &pointerDeviceRect, &displayRect);
cout << "get pointer device rects error code " << GetLastError() << endl;
cout << "coordinates: " << pointerDeviceRect.top<<endl;


Portion of code for getting the handle

C++
for (vector<RAWINPUTDEVICELIST>::iterator device_iterator(input_devices.begin());
            device_iterator != input_devices.end();
            ++device_iterator)
        {
            UINT info_size(sizeof(RID_DEVICE_INFO));
            if (GetRawInputDeviceInfo(device_iterator->hDevice, RIDI_DEVICEINFO, (LPVOID)&device_info, &info_size) == info_size)
            {
                // non-keyboard, non-mouse HID device?
                if (device_info.dwType == RIM_TYPEHID)
                {
                    if ((device_info.hid.dwVendorId == VENDOR_ID)
                        && (device_info.hid.dwProductId == PRODUCT_ID))
                    {
                        deviceHandle = device_iterator->hDevice;
                        break;
                    }
                }
            }
        }
Posted
Updated 31-Jul-18 10:52am
v3
Comments
CHill60 31-Jul-18 13:48pm    
When you say you are getting the correct handle to the device can you show us that bit of code?
Roger1990 31-Jul-18 14:54pm    
I updated that in the question for you

1 solution

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
C++
// Clearing the struct is optional here but does not harm
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]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900