0

I'd like to use libusb to retrieve information about my devices. I can read every descriptor and print every number associated inside theese descriptors. But I have troubles with the strings. How can I manage the string descriptors in a good way with c++?

I'd like to implement a simple function like this:

std::string get_string(std::uint8_t index);

which internally retrieves the string associated a index. The device handle is got from the attributes of the class(the function is a class member) and the buffer where the libusb_get_string_descriptor is allocated statically because seeing that the dimension is contained in a 8bit field the length must be at most 256 charachters, mustn't it?

How can I manage unicode with theese things? Any ideas? Is right the use of the std::string?

user2714602
  • 231
  • 4
  • 16
  • Sorry, you're right: buffer size is limited to 256 bytes by standard. `string.data()` isn't an implementation detail, it's part of the standard and it's documented so you may feel free to use it. The other option is to allocate it (`wchar_t* buffer`) to required size then pass that buffer to `string` constructor (but it'll be less efficient). – Adriano Repetti Sep 02 '13 at 21:04
  • If you have a C++11-compliant compiler, you could use `std::u16string`. The USB specifications require string descriptors to use the "UNICODE UTF16LE" encoding [USB3.1r1.0 - 9.6.9]. – dyp Sep 02 '13 at 22:14

0 Answers0