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.