Author Topic: Getting details of HID device can fail.  (Read 541 times)

bflorac

  • Newbie
  • *
  • Posts: 6
    • View Profile
Getting details of HID device can fail.
« on: March 22, 2015, 04:29:45 am »
When calling TnrHid.LoadDeviceCapabilities, it can be called with full mode to extract more details for ProductString, ManufacturerString and SerialNumberString. In doing so, it calls function HidD_GetCommonString() which uses the HID.DLL library make calls to the device to extract this info via GET_DESCRIPTOR requests.  However, HidD_GetCommonString allocates a string of 256 bytes. This should be no longer than 128 characters. According MS documentation :

The maximum possible number of characters in an embedded string is device specific. For USB devices, the maximum string length is 126 wide characters (not including the terminating NULL character).

This seems like a odd bug but I have seen USB devices that will either return nothing or a malformed packet if set too long. Off course, this is more like a bug in the device as it should handle this properly. On the otherhand, it is safer code to just not ask for more than could possibly be needed.

Roman Novgorodov

  • Engineer
  • Administrator
  • Hero Member
  • *****
  • Posts: 994
  • we will win
    • View Profile
    • Forums.nrCommLib.Com
Re: Getting details of HID device can fail.
« Reply #1 on: March 22, 2015, 06:19:02 pm »
Hello William

Thank you for detailed info.

We have checked msdn and reviewed some development forums.
It seems like your are right.

Next release will include fix for this issue.

Thank you.

Roman Novgorodov
DeepSoftware llc
DeepSoftware llc - The professional components for Delphi/CBuilder/.NET. The high quality custom software development.
Forums.nrCommLib.Com - DeepSoftware Tech Support Forum.

Roman Novgorodov

  • Engineer
  • Administrator
  • Hero Member
  • *****
  • Posts: 994
  • we will win
    • View Profile
    • Forums.nrCommLib.Com
Re: Getting details of HID device can fail.
« Reply #2 on: March 22, 2015, 06:29:01 pm »
From other side MSDN describes param as:

BufferLength [in]
    Specifies the length, in bytes, of a caller-allocated buffer provided at Buffer....

This means that 126 length of wide string has 252 length in bytes ...

We will check more .

Roman
« Last Edit: March 22, 2015, 06:31:20 pm by Roman Novgorodov »
DeepSoftware llc - The professional components for Delphi/CBuilder/.NET. The high quality custom software development.
Forums.nrCommLib.Com - DeepSoftware Tech Support Forum.

bflorac

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Getting details of HID device can fail.
« Reply #3 on: March 24, 2015, 01:40:05 am »
Just to confirm, I changed the value from 256 to 252 and it seems to now work for the HID device I'm working with.

Roman Novgorodov

  • Engineer
  • Administrator
  • Hero Member
  • *****
  • Posts: 994
  • we will win
    • View Profile
    • Forums.nrCommLib.Com
Re: Getting details of HID device can fail.
« Reply #4 on: March 24, 2015, 04:17:36 am »
Hello

Great!
We've already changed length from 255 to 252 in sources. But not tested with problem devices.
Thank you for feedback.

Roman Novgorodov
DeepSoftware llc
DeepSoftware llc - The professional components for Delphi/CBuilder/.NET. The high quality custom software development.
Forums.nrCommLib.Com - DeepSoftware Tech Support Forum.