- separate HID declarations for non-DDK build into re-usable headers;
- refactor initialisation/deinitialisation of HIDAPI;
- make all the comments consistent (C-style only);
Fixes a segfault that happens when hid_open_path is called on a previously disconnected device.
This is a regression caused by:
b600727 - Win32: Fix memory leak in `free_hid_device` (#361)
Co-authored-by: Megamouse <studienricky89@googlemail.de>
- It appears when the numbered reports aren't used,
WinAPI returns size of the report excluding the data[0] which contains 0,
as an indication that numbered reports aren't used;
Explicity count that byte in the result.
Fixes: #328
Deleted DDK build scripts, support files and documentation for it,
as it wasn't working of-the-box with recent tool-sets from MS anyway.
Still keeping `HIDAPI_USE_DDK` macro in the code,
as it still _can_ be used if the build configuration is setup properly.
Resolves: #49
This fixed a compiler warning when using MSYS2 MinGW-w64 compiler as mentioned in issue #289.
Since we changed strncpy to memcpy, it is not necessary to disable warning 4996 for MSVC.
In some cases HidD_GetSerialNumberString/HidD_GetManufacturerString/HidD_GetProductString can fail.
For example if we have Bluetooth LE gamepad on Windows.
In this case we are currently returning not initialized strings in `hid_device_info`.
- 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.
Older versions of MSVC (for example when using Visual Studio 10) don't
yet support variable declaration in the middle of blocks:
hidapi\windows\hid.c(845) : error C2275: 'BOOL' : illegal use of this type as an expression
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\windef.h(153) : see declaration of 'BOOL'
Move the declaration of res to the beginning of the function. Like in
hid_get_feature_report, only res is moved, essentially ignoring the #if
0 block (or assuming it will never be enabled).
This allows to build the test program with toolchains that don't have
C++ support.
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
Right now, in hid_open it is checked if the connected devices have
"HIDClass" driver name. This is true for composite devices, but some
simple HID devices only have "Mouse" or "Keyboard" driver name.
One of devices that cannot be opened is Dell MS116t, but any mouse which
is not part of composite device can be affected.
With this change, one can enumerate and open these devices.
Signed-off-by: Kubicz, Filip <filip.kubicz@nordicsemi.no>
Modern Windows implementations don't allow opening HID devices in
READ/WRITE mode if they are claimed by the system. Examples of such
devices include keyboards and mice.
However, these devices can be opened without READ/WRITE permissions, in
order to allow sending and receiving feature reports.
If open_device() fails, retry without requesting READ/WRITE permissions.
This inverts the logic of the parameter to open_device().
It is a refactor of #44 by @pqu.
Signed-off-by: Sean Cross <sean@xobs.io>