Click here to Skip to main content
15,886,919 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have the problem that I can't seem to make GetRawInputDeviceInfo work in combination with RIDI_DEVICEINFO (to try to retrieve a RID_DEVICE_INFO) is not working at all.

I get the error -1 back from the function, what should mean that there is not enough space to store the RID_DEVICE_INFO, buy I tried already to increase it to the more then needed but the effect the same.

I used the following DLLImports :

C#
[DllImport("User32.dll")]
extern static uint GetRawInputDeviceInfo(IntPtr hDevice, uint uiCommand, IntPtr pData, ref uint pcbSize);

[DllImport("User32.dll")]
unsafe extern static uint GetRawInputDeviceInfo(IntPtr hDevice, uint uiCommand, IntPtr pData, IntPtr pcbSize);

Both with no result, but when I try these with RIDI_DEVICENAME they both work just fine. In this case I call the function like this :

first to get the size:
C#
GetRawInputDeviceInfo(rid.hDevice, RIDI_DEVICENAME, IntPtr.Zero, pSize);


and then :
C#
GetRawInputDeviceInfo(rid.hDevice, RIDI_DEVICENAME, pData, pSize);


to get the name. Both work fine, but when I call the function like this :

C#
int intReturn = (int)GetRawInputDeviceInfo(rid.hDevice, RIDI_DEVICEINFO, IntPtr.Zero, pInfoSize);
intReturn = (int)GetRawInputDeviceInfo(rid.hDevice, RIDI_DEVICEINFO, pInfoData, pInfoSize);

Then at first I get 0 into intReturn and also can get the correct size, but then I get -1 into return, and whan I do a PtrToStructure it just returns wrong and seemingly random values.

Also when I after that do a GetLastWin32Error(), it return sometime 1008 or 87 , what also seems not to make any logic to me, because I don't see where I could have made the wrong parameters.

I defined RIDI_DEVICENAME and RIDI_DEVICEINFO as :

C#
internal const uint RIDI_DEVICENAME = 0x20000007;
internal const uint RIDI_DEVICEINFO = 0x2000000b;

Can anyone help with this problem or show me a working C# example for GetRawInputDeviceInfo ?

Thanks, Peter
Posted
Updated 3-Sep-12 23:31pm
v2

1 solution

Here is the way that I am using the RIDI_DEVICEINFO parameter with the GetRawInputDeviceInfo() function. What I found was that the cbSize member of the RIDI_DEVICEINFO struct needed to be initialized with the size of the struct.

Just now looking at the Microsoft MSDN on-line documentation it mentions the following:

Quote:
If uiCommand is RIDI_DEVICEINFO, set the cbSize member of RID_DEVICE_INFO to sizeof(RID_DEVICE_INFO) before calling GetRawInputDeviceInfo.


C++
UINT             cbDataSize = 1000;
RID_DEVICE_INFO  DevInfo = {0};

DevInfo.cbSize = cbDataSize = sizeof(DevInfo);  // specify the buffer size
GetRawInputDeviceInfo(pRawInputDeviceList[i].hDevice, RIDI_DEVICEINFO, &DevInfo, &cbDataSize);
 
Share this answer
 

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