@@ -97,6 +97,7 @@ static HidD_GetManufacturerString_ HidD_GetManufacturerString;
9797static HidD_GetProductString_ HidD_GetProductString ;
9898static HidD_SetFeature_ HidD_SetFeature ;
9999static HidD_GetFeature_ HidD_GetFeature ;
100+ static HidD_SetOutputReport_ HidD_SetOutputReport ;
100101static HidD_GetInputReport_ HidD_GetInputReport ;
101102static HidD_GetIndexedString_ HidD_GetIndexedString ;
102103static HidD_GetPreparsedData_ HidD_GetPreparsedData ;
@@ -150,6 +151,7 @@ static int lookup_functions()
150151 RESOLVE (hid_lib_handle , HidD_GetProductString );
151152 RESOLVE (hid_lib_handle , HidD_SetFeature );
152153 RESOLVE (hid_lib_handle , HidD_GetFeature );
154+ RESOLVE (hid_lib_handle , HidD_SetOutputReport );
153155 RESOLVE (hid_lib_handle , HidD_GetInputReport );
154156 RESOLVE (hid_lib_handle , HidD_GetIndexedString );
155157 RESOLVE (hid_lib_handle , HidD_GetPreparsedData );
@@ -1313,6 +1315,45 @@ int HID_API_EXPORT HID_API_CALL hid_get_feature_report(hid_device *dev, unsigned
13131315 return hid_get_report (dev , IOCTL_HID_GET_FEATURE , data , length );
13141316}
13151317
1318+ int HID_API_EXPORT HID_API_CALL hid_send_output_report (hid_device * dev , const unsigned char * data , size_t length )
1319+ {
1320+ BOOL res = FALSE;
1321+ unsigned char * buf ;
1322+ size_t length_to_send ;
1323+
1324+ if (!data || !length ) {
1325+ register_string_error (dev , L"Zero buffer/length" );
1326+ return -1 ;
1327+ }
1328+
1329+ register_string_error (dev , NULL );
1330+
1331+ /* Windows expects at least caps.OutputeportByteLength bytes passed
1332+ to HidD_SetOutputReport(), even if the report is shorter. Any less sent and
1333+ the function fails with error ERROR_INVALID_PARAMETER set. Any more
1334+ and HidD_SetOutputReport() silently truncates the data sent in the report
1335+ to caps.OutputReportByteLength. */
1336+ if (length >= dev -> output_report_length ) {
1337+ buf = (unsigned char * ) data ;
1338+ length_to_send = length ;
1339+ } else {
1340+ if (dev -> write_buf == NULL )
1341+ dev -> write_buf = (unsigned char * ) malloc (dev -> output_report_length );
1342+ buf = dev -> write_buf ;
1343+ memcpy (buf , data , length );
1344+ memset (buf + length , 0 , dev -> output_report_length - length );
1345+ length_to_send = dev -> output_report_length ;
1346+ }
1347+
1348+ res = HidD_SetOutputReport (dev -> device_handle , (PVOID )buf , (DWORD ) length_to_send );
1349+ if (!res ) {
1350+ register_string_error (dev , L"HidD_SetOutputReport" );
1351+ return -1 ;
1352+ }
1353+
1354+ return (int ) length ;
1355+ }
1356+
13161357int HID_API_EXPORT HID_API_CALL hid_get_input_report (hid_device * dev , unsigned char * data , size_t length )
13171358{
13181359 /* We could use HidD_GetInputReport() instead, but it doesn't give us an actual length, unfortunately */
0 commit comments