问题描述
我试图在c ++中调用GetPointerDeviceRects api,以获得触摸数字化仪的范围。它需要3个参数。一个是手柄。我能够使用GetRawInputDeviceList获取设备的正确句柄。至于其他参数,我已将它们声明为如下面的代码提取中所示。我收到错误代码87,这意味着无效的参数。你能帮我解决这个错误。
我尝试过的事情:
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
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;
}
}
}
}
推荐答案
pData [in,out,optional]
类型:LPVOID
指向包含uiCommand指定信息的缓冲区的指针。如果uiCommand是RIDI_DEVICEINFO,请在调用GetRawInputDeviceInfo之前将RID_DEVICE_INFO的cbSize成员设置为sizeof(RID_DEVICE_INFO)。
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
// 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);
您没有显示获取设备句柄和调用 GetPointerDeviceRects()$之间的完整关系c $ c>。
但您对 GetRawInputDeviceInfo()
的所有调用都失败,错误 ERROR_INVALID_PARAMETER
这样就不会设置/更改 deviceHandle
变量。
除了通过一个不正确的初始化结构,你又犯了一个错误:
你没有正确处理错误。 GetLastError()
返回的值永远不会被清除,只会在API函数失败时设置。因此,只有在API函数通过返回值指示失败时才必须调用它。并且必须在调用任何其他API函数之前调用它(这通常意味着:任何其他函数,因为它们也可以调用API函数)。
[/ 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]
这篇关于调用getpointerdevicerects时ERROR_INVALID_PARAMETER的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!