Fixed Windows XP compatibility with recent hidapi commit

This commit is contained in:
Sam Lantinga 2021-01-02 09:58:08 -08:00
parent 3edf337d66
commit f0b6c78733
1 changed files with 13 additions and 3 deletions

View File

@ -932,13 +932,23 @@ int HID_API_EXPORT HID_API_CALL hid_get_feature_report(hid_device *dev, unsigned
void HID_API_EXPORT HID_API_CALL hid_close(hid_device *dev)
{
DWORD bytes_read = 0;
typedef BOOL (WINAPI *CancelIoEx_t)(HANDLE hFile, LPOVERLAPPED lpOverlapped);
CancelIoEx_t CancelIoExFunc = (CancelIoEx_t)GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")), "CancelIoEx");
if (!dev)
return;
CancelIoEx(dev->device_handle, NULL);
if (dev->read_pending)
if (CancelIoExFunc) {
CancelIoExFunc(dev->device_handle, NULL);
} else {
/* Windows XP, this will only cancel I/O on the current thread */
CancelIo(dev->device_handle);
}
if (dev->read_pending) {
DWORD bytes_read = 0;
GetOverlappedResult(dev->device_handle, &dev->ol, &bytes_read, TRUE/*wait*/);
}
free_hid_device(dev);
}