Author Topic: Anything better than HIDAPI today?  (Read 4165 times)

bpaddock

  • Frequent Contributor
  • ****
  • Posts: 66
Anything better than HIDAPI today?
« on: September 10, 2019, 01:10:32 pm »
I've been using Signal11's HIDAPI for years.
Sadly it looks like it has been abandoned by its author.
As well as saying in the past "won't fix" some issues that really need fixed.

Today it won't even compile with modern GCC versions without modification,
as GCC points out some dubious coding practices.  From GCC 8.2:

HIDAPI/hid.c: In function 'hid_enumerate':
HIDAPI/hid.c:449:5: error: 'strncpy' specified bound depends on the length of the source argument [-Werror=stringop-over
flow=]
     strncpy(cur_dev->path, str, len+1);
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HIDAPI/hid.c:447:11: note: length computed here
     len = strlen(str);
           ^~~~~~~~~~~

While that is fixable by replacing strncpy with memcpy, I'm wondering if there is something better supported for communication with HID devices today?

I must be able to support Windows7 machines that may have never had any updates, ruling out WinUSB?
Must also run as a normal user and I can't install anything for some other limitations.


For completeness for those trying to get HIDAPI to compile,
one of the other issues is its dubious use of macros.

To compile with 8.1 or later must add a cast to (void *) to the RESOLVE macro.

#define RESOLVE(x) x = (x##_)(void *)GetProcAddress(lib_handle,  #x); if (!x) return -1;

RESOLVE(HidD_GetSerialNumberString);

That head scratchier expands to, as one example:

  HidD_GetSerialNumberString = (HidD_GetSerialNumberString_)(void *)GetProcAddress(lib_handle, "HidD_GetSerialNumberString"); if (!HidD_GetSerialNumberString) return -1;;

in case your head was hurting trying to figure it out...
The double semi-colon would also technically be an error.

« Last Edit: September 10, 2019, 01:21:14 pm by bpaddock »

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Anything better than HIDAPI today?
« Reply #1 on: September 10, 2019, 07:49:45 pm »
I think you're probably aware of my HID example code here:

http://www.janaxelson.com/hidpage.htm#MyExampleCode

I have links to other HID host code here:

http://www.janaxelson.com/hidpage.htm#OtherHIDCode

You mentioned WinUSB, indicating that perhaps you're not tied to HID. Another option could be virtual COM port:

http://www.janaxelson.com/serport.htm#usb_virtual_com_ports

bpaddock

  • Frequent Contributor
  • ****
  • Posts: 66
Re: Anything better than HIDAPI today?
« Reply #2 on: December 02, 2019, 08:14:55 am »
Due to the original author abandoning HIDAPI the
LibUSB project has forked it and applied the long
lingering patches needed:

https://github.com/libusb/hidapi

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Anything better than HIDAPI today?
« Reply #3 on: December 02, 2019, 01:43:54 pm »
Thanks for sharing this