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