Imrpoved HID device friendly name.
authorStephaneLenclud
Thu, 05 Mar 2015 10:12:37 +0100
changeset 71c28dd93b94c5
parent 70 e0a7b35f90dd
child 72 471b1d45c46a
Imrpoved HID device friendly name.
HidDevice.cs
RawInput.cs
     1.1 --- a/HidDevice.cs	Wed Mar 04 20:52:24 2015 +0100
     1.2 +++ b/HidDevice.cs	Thu Mar 05 10:12:37 2015 +0100
     1.3 @@ -243,9 +243,20 @@
     1.4                  FriendlyName = Product + suffix;
     1.5              }
     1.6              else
     1.7 -            {
     1.8 -                //No proper name just use the device ID instead
     1.9 -                FriendlyName = "0x" + ProductId.ToString("X4") + suffix;
    1.10 +            {   
    1.11 +                //Extract friendly name from name
    1.12 +                char[] delimiterChars = { '#', '&'};
    1.13 +                string[] words = Name.Split(delimiterChars);
    1.14 +                if (words.Length >= 2)
    1.15 +                {
    1.16 +                    //Use our name sub-string to describe this device
    1.17 +                    FriendlyName = words[1] + " - 0x" + ProductId.ToString("X4") + suffix;
    1.18 +                }
    1.19 +                else
    1.20 +                {
    1.21 +                    //No proper name just use the device ID instead
    1.22 +                    FriendlyName = "0x" + ProductId.ToString("X4") + suffix;
    1.23 +                }
    1.24              }
    1.25  
    1.26          }
     2.1 --- a/RawInput.cs	Wed Mar 04 20:52:24 2015 +0100
     2.2 +++ b/RawInput.cs	Thu Mar 05 10:12:37 2015 +0100
     2.3 @@ -104,7 +104,7 @@
     2.4              int result = Win32.Function.GetRawInputDeviceInfo(hDevice, RawInputDeviceInfoType.RIDI_PREPARSEDDATA, IntPtr.Zero, ref ppDataSize);
     2.5              if (result != 0)
     2.6              {
     2.7 -                Debug.WriteLine("Failed to get raw input pre-parsed data size" + result + Marshal.GetLastWin32Error());
     2.8 +                Debug.WriteLine("Failed to get raw input pre-parsed data size: " + result + " : " + Marshal.GetLastWin32Error());
     2.9                  return IntPtr.Zero;
    2.10              }
    2.11  
    2.12 @@ -112,7 +112,7 @@
    2.13              result = Win32.Function.GetRawInputDeviceInfo(hDevice, RawInputDeviceInfoType.RIDI_PREPARSEDDATA, ppData, ref ppDataSize);
    2.14              if (result <= 0)
    2.15              {
    2.16 -                Debug.WriteLine("Failed to get raw input pre-parsed data" + result + Marshal.GetLastWin32Error());
    2.17 +                Debug.WriteLine("Failed to get raw input pre-parsed data: " + result + " : " + Marshal.GetLastWin32Error());
    2.18                  return IntPtr.Zero;
    2.19              }
    2.20              return ppData;