Why would WinUsb_Initialize fail with ERROR_INVALID_PARAMETER

I’m using WinUSB to talk to a bulk transfer device we’re developing for a
client. After plugging the device in, I can do a CreateFile and
WinUsb_Initialize successfully, and obtain data from the device.

But at some point later on (several minutes, maybe), even though I can still
open the device with CreateFile, WinUsb_Initialize returns FALSE and
GetLastError returns ERROR_INVALID_PARAMETER.

Here’s a code fragment:

HANDLE hDevice, hCompletionPort;
WINUSB_INTERFACE_HANDLE ihDevice;

// psiddd->DevicePath is obtained from SetupDiGetDeviceInterfaceDetail;
// it appears to be reasonable, and CreateFile succeeds using this path
hDevice = CreateFile(psiddd->DevicePath, GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
OPEN_EXISTING,
FILE_FLAG_OVERLAPPED, NULL);
if (hDevice != INVALID_HANDLE_VALUE)
{
hCompletionPort = CreateIoCompletionPort(hDevice, NULL, 0, 0);
if (hCompletionPort != NULL)
{
if (WinUsb_Initialize(hDevice, &ihDevice))
{
// do more stuff here
}
else
{
dwRet = GetLastError());
// dwRet ends up as 87 (0x57), ERROR_INVALID_PARAMETER
}
}
}

If I unplug and replug the device (device stays powered on (self-powered)),
it works again for a while, but then fails again at some point. I am
closing the device before exiting my test program. But even that shouldn’t
matter, since when my test app exits, any open handles should be closed
(WinUsb.sys will get the usual cleanup/close IRPs), right?

What would make WinUsb_Initialize return FALSE / ERROR_INVALID_PARAMETER on
a valid device handle?

-Dan

WinUsb_Initialize doesn’t return this error value itself. This means it
must be getting that result from the driver. Looking at the driver
code, I don’t see where this result would happen either.

If you are certain that this is where the error is occurring, then I
would like to work with you offline to debug the issue.

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Daniel E.
Germann
Sent: Wednesday, January 10, 2007 4:36 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] Why would WinUsb_Initialize fail with
ERROR_INVALID_PARAMETER

I’m using WinUSB to talk to a bulk transfer device we’re developing for
a
client. After plugging the device in, I can do a CreateFile and
WinUsb_Initialize successfully, and obtain data from the device.

But at some point later on (several minutes, maybe), even though I can
still
open the device with CreateFile, WinUsb_Initialize returns FALSE and
GetLastError returns ERROR_INVALID_PARAMETER.

Here’s a code fragment:

HANDLE hDevice, hCompletionPort;
WINUSB_INTERFACE_HANDLE ihDevice;

// psiddd->DevicePath is obtained from SetupDiGetDeviceInterfaceDetail;
// it appears to be reasonable, and CreateFile succeeds using this path
hDevice = CreateFile(psiddd->DevicePath, GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
OPEN_EXISTING,
FILE_FLAG_OVERLAPPED, NULL);
if (hDevice != INVALID_HANDLE_VALUE)
{
hCompletionPort = CreateIoCompletionPort(hDevice, NULL, 0, 0);
if (hCompletionPort != NULL)
{
if (WinUsb_Initialize(hDevice, &ihDevice))
{
// do more stuff here
}
else
{
dwRet = GetLastError());
// dwRet ends up as 87 (0x57), ERROR_INVALID_PARAMETER
}
}
}

If I unplug and replug the device (device stays powered on
(self-powered)),
it works again for a while, but then fails again at some point. I am
closing the device before exiting my test program. But even that
shouldn’t
matter, since when my test app exits, any open handles should be closed
(WinUsb.sys will get the usual cleanup/close IRPs), right?

What would make WinUsb_Initialize return FALSE / ERROR_INVALID_PARAMETER
on
a valid device handle?

-Dan


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer