SDL: hidapi: update hid_write() for windows from mainstream.

From 13c5d1092fc3ff7b5268ae2c73ecd71d83782a62 Mon Sep 17 00:00:00 2001
From: Ozkan Sezer <[EMAIL REDACTED]>
Date: Sun, 29 Sep 2024 17:56:40 +0300
Subject: [PATCH] hidapi: update hid_write() for windows from mainstream.

Returns bytes_written if WriteFile returns synchronously
Relevant mainstream discussions:
	https://github.com/libusb/hidapi/pull/697
	https://github.com/libusb/hidapi/issues/695
---
 src/hidapi/windows/hid.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/hidapi/windows/hid.c b/src/hidapi/windows/hid.c
index 832878bbc2b9f..3376ba96e55ea 100644
--- a/src/hidapi/windows/hid.c
+++ b/src/hidapi/windows/hid.c
@@ -1282,7 +1282,7 @@ int HID_API_EXPORT HID_API_CALL hid_write(hid_device *dev, const unsigned char *
 		length = dev->output_report_length;
 	}
 
-	res = WriteFile(dev->device_handle, buf, (DWORD) length, NULL, &dev->write_ol);
+	res = WriteFile(dev->device_handle, buf, (DWORD) length, &bytes_written, &dev->write_ol);
 
 	if (!res) {
 		if (GetLastError() != ERROR_IO_PENDING) {
@@ -1291,6 +1291,9 @@ int HID_API_EXPORT HID_API_CALL hid_write(hid_device *dev, const unsigned char *
 			goto end_of_function;
 		}
 		overlapped = TRUE;
+	} else {
+		/* WriteFile() succeeded synchronously. */
+		function_result = bytes_written;
 	}
 
 	if (overlapped) {