diff --git a/device/win_usb/win_usb.cpp b/device/win_usb/win_usb.cpp index 64bd069..1ca776e 100644 --- a/device/win_usb/win_usb.cpp +++ b/device/win_usb/win_usb.cpp @@ -757,13 +757,31 @@ int usb_device::transfer_control(uint8_t type, uint8_t req, uint16_t val, uint16 irp.uLength = len; irp.uOffset = val; if (DeviceIoControl((HANDLE)handle_, IOCTL_SEND_USB_REQUEST, &irp, sizeof(irp), data, len, oc->io_bytes(), oc->over_lapped())) - ret = *oc->io_bytes(); + { + if (irp.fTransferDirectionIn) + { + GetOverlappedResult((HANDLE)handle_, oc->over_lapped(), oc->io_bytes(), FALSE); + ret = *oc->io_bytes(); + } + else + { + ret = len; + } + } else if (GetLastError() == ERROR_IO_PENDING) { ret = WaitForSingleObject(oc->over_lapped()->hEvent, timeout) == WAIT_TIMEOUT ? LIBUSB_ERROR_TIMEOUT : *oc->io_bytes(); } else - ret = LIBUSB_ERROR_PIPE; + { + io = GetLastError(); + if (io == ERROR_ACCESS_DENIED) + ret = LIBUSB_ERROR_ACCESS; + else if (io == ERROR_SEM_TIMEOUT) + ret = LIBUSB_ERROR_TIMEOUT; + else + ret = LIBUSB_ERROR_PIPE; + } oc->release(); }