Skip to content

Commit

Permalink
FIX Compiler Warnings on Windows
Browse files Browse the repository at this point in the history
- cast hidapi supplied size_t parameters to DWORD when calling Windows
  API functions
- cast size_t return variables in `hid_read_timeout` and
  `hid_send_feature_report` to int in order to match hidapi signature.
  • Loading branch information
Stanley Pinchak authored and Youw committed Aug 13, 2020
1 parent 24a822c commit ad27b46
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions windows/hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,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, length, NULL, &ol);
res = WriteFile(dev->device_handle, buf, (DWORD) length, NULL, &ol);

if (!res) {
if (GetLastError() != ERROR_IO_PENDING) {
Expand Down Expand Up @@ -697,7 +697,7 @@ int HID_API_EXPORT HID_API_CALL hid_read_timeout(hid_device *dev, unsigned char
dev->read_pending = TRUE;
memset(dev->read_buf, 0, dev->input_report_length);
ResetEvent(ev);
res = ReadFile(dev->device_handle, dev->read_buf, dev->input_report_length, &bytes_read, &dev->ol);
res = ReadFile(dev->device_handle, dev->read_buf, (DWORD) dev->input_report_length, &bytes_read, &dev->ol);

if (!res) {
if (GetLastError() != ERROR_IO_PENDING) {
Expand Down Expand Up @@ -751,7 +751,7 @@ int HID_API_EXPORT HID_API_CALL hid_read_timeout(hid_device *dev, unsigned char
return -1;
}

return copy_len;
return (int) copy_len;
}

int HID_API_EXPORT HID_API_CALL hid_read(hid_device *dev, unsigned char *data, size_t length)
Expand All @@ -767,13 +767,13 @@ int HID_API_EXPORT HID_API_CALL hid_set_nonblocking(hid_device *dev, int nonbloc

int HID_API_EXPORT HID_API_CALL hid_send_feature_report(hid_device *dev, const unsigned char *data, size_t length)
{
BOOL res = HidD_SetFeature(dev->device_handle, (PVOID)data, length);
BOOL res = HidD_SetFeature(dev->device_handle, (PVOID)data, (DWORD) length);
if (!res) {
register_error(dev, "HidD_SetFeature");
return -1;
}

return length;
return (int) length;
}


Expand All @@ -795,8 +795,8 @@ int HID_API_EXPORT HID_API_CALL hid_get_feature_report(hid_device *dev, unsigned

res = DeviceIoControl(dev->device_handle,
IOCTL_HID_GET_FEATURE,
data, length,
data, length,
data, (DWORD) length,
data, (DWORD) length,
&bytes_returned, &ol);

if (!res) {
Expand Down Expand Up @@ -844,8 +844,8 @@ int HID_API_EXPORT HID_API_CALL hid_get_input_report(hid_device *dev, unsigned c

res = DeviceIoControl(dev->device_handle,
IOCTL_HID_GET_INPUT_REPORT,
data, length,
data, length,
data, (DWORD) length,
data, (DWORD) length,
&bytes_returned, &ol);

if (!res) {
Expand Down Expand Up @@ -886,7 +886,7 @@ int HID_API_EXPORT_CALL HID_API_CALL hid_get_manufacturer_string(hid_device *dev
{
BOOL res;

res = HidD_GetManufacturerString(dev->device_handle, string, sizeof(wchar_t) * MIN(maxlen, MAX_STRING_WCHARS));
res = HidD_GetManufacturerString(dev->device_handle, string, sizeof(wchar_t) * (DWORD) MIN(maxlen, MAX_STRING_WCHARS));
if (!res) {
register_error(dev, "HidD_GetManufacturerString");
return -1;
Expand All @@ -899,7 +899,7 @@ int HID_API_EXPORT_CALL HID_API_CALL hid_get_product_string(hid_device *dev, wch
{
BOOL res;

res = HidD_GetProductString(dev->device_handle, string, sizeof(wchar_t) * MIN(maxlen, MAX_STRING_WCHARS));
res = HidD_GetProductString(dev->device_handle, string, sizeof(wchar_t) * (DWORD) MIN(maxlen, MAX_STRING_WCHARS));
if (!res) {
register_error(dev, "HidD_GetProductString");
return -1;
Expand All @@ -912,7 +912,7 @@ int HID_API_EXPORT_CALL HID_API_CALL hid_get_serial_number_string(hid_device *de
{
BOOL res;

res = HidD_GetSerialNumberString(dev->device_handle, string, sizeof(wchar_t) * MIN(maxlen, MAX_STRING_WCHARS));
res = HidD_GetSerialNumberString(dev->device_handle, string, sizeof(wchar_t) * (DWORD) MIN(maxlen, MAX_STRING_WCHARS));
if (!res) {
register_error(dev, "HidD_GetSerialNumberString");
return -1;
Expand All @@ -925,7 +925,7 @@ int HID_API_EXPORT_CALL HID_API_CALL hid_get_indexed_string(hid_device *dev, int
{
BOOL res;

res = HidD_GetIndexedString(dev->device_handle, string_index, string, sizeof(wchar_t) * MIN(maxlen, MAX_STRING_WCHARS));
res = HidD_GetIndexedString(dev->device_handle, string_index, string, sizeof(wchar_t) * (DWORD) MIN(maxlen, MAX_STRING_WCHARS));
if (!res) {
register_error(dev, "HidD_GetIndexedString");
return -1;
Expand Down

0 comments on commit ad27b46

Please sign in to comment.