tags:

views:

23

answers:

0

I'm trying to use the Windows Driver Kit HID functions to get the state of a Saitek X52 joystick on x86 Windows 7.

I can get ReadFile to return some of the button presses, but not all.

When I use a USB traffic analyzer (specifically USB Monitor), I can see all of the button presses.

Additionally, when I hook the joystick up to a Windows XP VM, the same code I'm running on Windows 7 DOES return all the button presses.

Does anybody have any clue what the USB traffic analyzer could be doing differently than the code that follows?

I have also tried using HidD_GetInputReport instead of ReadFile, but that just causes a report full of NULLs to be returned.

Most of my code is lifted straight from Microsoft hclient example.

Here's what I'm thinking are the sailient parts:

HidDevice->HidDevice = CreateFile (DevicePath,
                                   GENERIC_READ | GENERIC_WRITE,
                                   0,
                                   NULL,        // no SECURITY_ATTRIBUTES structure
                                   OPEN_EXISTING, // No special create flags
                                   0,   
                                   NULL);       // No template file



DWORD    bytesRead;

if (!ReadFile (HidDevice->HidDevice,
          HidDevice->InputReportBuffer,
          HidDevice->Caps.InputReportByteLength,
          &bytesRead,
          NULL)) 
{
        DWORD dw = GetLastError(); 
        return FALSE;
}

ULONG       numUsages; // Number of usages returned from GetUsages.
ULONG       i;
UCHAR       reportID;


reportID = ReportBuffer[0];

for (i = 0; i < DataLength; i++, Data++) 
{
    if (reportID == Data->ReportID) 
    {
        if (Data->IsButtonData) 
        {
            numUsages = Data->ButtonData.MaxUsageLength;

            Data->Status = HidP_GetUsages (ReportType,
                                           Data->UsagePage,
                                           0, // All collections
                                           Data->ButtonData.Usages,
                                           &numUsages,
                                           Ppd,
                                           ReportBuffer,
                                           ReportBufferLength);


            Data->ButtonData.MaxUsageLength = numUsages;

        }
    }
}