'Problem with CancelIoEx function on some platforms

I work with usb device and use async functions of usbdk driver for I/O operations. I have a problem with canceling of operations on some win platforms. Im using function CancelIoEx for that and it works fine for some part of users but for some it doesn't work. The data is either transmitted completely or not transmitted at all. No intermediate values. CancelIoEx returns 1 in both cases. AbortPipe by usbdk lib doesn't work at all.

HANDLE redirectHandle = usbdk_helper.StartRedirect(&devID);
HANDLE systemHandle = usbdk_helper.GetRedirectorSystemHandle(redirectHandle);
unsigned char* buffer = static_cast<unsigned char*>(std::malloc(0x08 + length));
OVERLAPPED overlapped;
USB_DK_TRANSFER_REQUEST request { 0 };
DWORD overlappedTransfered = 0;

overlapped.hEvent = CreateEvent(NULL, TRUE, FALSE, L"USBEVENT");

...
...
...

request.Buffer = buffer;
request.BufferLength = 0x08 + length;
request.TransferType = ControlTransferType;

auto res = usbdk_helper.WritePipe(redirectHandle, &request, &overlapped); //return TransferSuccessAsync
auto abort_res = CancelIoEx(systemHandle, &overlapped); //Return TRUE
auto event_res = WaitForSingleObject(overlapped.hEvent, INFINITE); //return WAIT_OBJECT_0
std::cout << "count transfered bytes: " << std::dec << request.Result.GenResult.BytesTransferred << std::endl; //0 or full for "bad", or 0 or intermediate for "correct"


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source