Reputation: 21000
I'm messing around with a USB RFID scanner and trying to read input with raw input, so far I have this
#define _WIN32_WINNT 0x0601
#include <windows.h>
#include <stdio.h>
int main(void)
{
PRAWINPUTDEVICELIST pRawInputDeviceList;
PUINT puiNumDevices, pcbSize;
UINT cbSize = sizeof(RAWINPUTDEVICELIST);
char *pData[1000];
GetRawInputDeviceList(NULL, puiNumDevices, cbSize);
pRawInputDeviceList = malloc(cbSize * *puiNumDevices);
GetRawInputDeviceList(pRawInputDeviceList, puiNumDevices, cbSize);
// gives a correct RIM_TYPE for all devices 0-7 (GetRawInputDeviceList returns 8 devices for me)
printf("%I32u\n", pRawInputDeviceList[0].dwType);
GetRawInputDeviceInfo(pRawInputDeviceList[1].hDevice, RIDI_DEVICENAME, pData, pcbSize);
// gives a huge number (garbage?), should be the length of the name
printf("%u\n", pcbSize);
// "E" in my case
printf("%s\n", pData);
// error 87, apparently ERROR_INVALID_PARAMETER
printf("%I32u\n", GetLastError());
return 0;
}
Upvotes: 0
Views: 1368
Reputation: 12570
When you call GetRawInputDeviceInfo
, it expects pcbSize
to be a pointer. You have it as a pointer, but its not pointing to anything. Try this:
pcbSize
(everywhere).UINT cbDataSize = 1000
. This is the size of your pData
array.GetRawInputDeviceInfo
, use &cbDataSize
. This takes the address of cbDataSize
, the address is a pointer.printf("%u\n", pcbSize);
to printf("%u\n", cbDataSize);
.See how that works for you.
[edit]
Also, you should do the same thing for puiNumDevices
. Instead, create a UINT
called uiNumDevices
. Use &uiNumDevices
where the functions expect pointers.
Upvotes: 1
Reputation: 13357
I am going to go out on a limb here and guess that this thing may actually be a HID device. Do you know if it is?
HID Devices are actually pretty easy to talk to; you connect to them via CreateFile() -- the same way that you would open a COM port -- and then just ReadFile() to get data.
Most of the problem is figuring out the correct path to connect to. It's actually a value called DevicePath that you get from SetupDiGetDeviceInterfaceDetail().
A rough map of it looks like this:
HidD_GetHidGuid() to get the HID guid
SetupDiGetClassDevs() to get the list of dev
Looping through devs, until you find yours:
If it is, remember it, and use ReadFile() to get data.
Upvotes: 0