I am writing a .NET application that can communicate with HID devices. I want to be able to retrieve and parse the Manufactures String from the device firmware. I know that in the hid.dll there is a method called HidD_GetManufacturerString. MSDN describes this method as follows:
BOOLEAN HidD_GetManufacturerString(
IN HANDLE HidDeviceObject,
OUT PVOID Buffer,
IN ULONG BufferLength
);
The wrapper i am using for this method looks like this...
[DllImport("hid.dll", SetLastError = true)]
internal static extern Boolean HidD_GetManufacturerString(
SafeFileHandle hFile,
Byte[] SerialNumber,
Int32 SerianNumberLength);
I need to know two things. First, how do I know what size to initialize the SerialNumber buffer to? When I do operations like GetFeatureReport I know what size to make the buffer because I can retrieve the max Feature Report Length from the device Attributes using HidD_GetAttributes(); Unfortunatly, this method doesn't give me any info of the length of the Manufacturer string, serial number string, product name string, etc.
My second question is, what is the correct way to parse the byte array that is returned into a string? I tried using
System.Text.Encoding.ASCII.GetString(MfrBuffer)
but I get a strange result. For a product manufacturered by Dell my string looks like this "D\0e\0l\0l\0\0\0\0\0..." the "\0" continue on to the end of the buffer that I passed. How do I parse this to "Dell"?