Was trying to get manufacturer string.
authorsl
Sat, 06 Dec 2014 03:26:27 +0100
changeset 23743cadfacda0
parent 22 8b2a3da54187
child 24 974f5fdaebfb
Was trying to get manufacturer string.
RawInput.cs
RemoteControlDevice.cs
Win32Hid.cs
Win32RawInput.cs
     1.1 --- a/RawInput.cs	Sat Dec 06 02:46:46 2014 +0100
     1.2 +++ b/RawInput.cs	Sat Dec 06 03:26:27 2014 +0100
     1.3 @@ -68,7 +68,7 @@
     1.4                  uint deviceInfoSize = (uint)Marshal.SizeOf(typeof(RID_DEVICE_INFO));
     1.5                  deviceInfoBuffer = Marshal.AllocHGlobal((int)deviceInfoSize);
     1.6  
     1.7 -                int res = Win32.Function.GetRawInputDeviceInfoW(hDevice, Const.RIDI_DEVICEINFO, deviceInfoBuffer, ref deviceInfoSize);
     1.8 +                int res = Win32.Function.GetRawInputDeviceInfo(hDevice, Const.RIDI_DEVICEINFO, deviceInfoBuffer, ref deviceInfoSize);
     1.9                  if (res <= 0)
    1.10                  {
    1.11                      Debug.WriteLine("WM_INPUT could not read device info: " + Marshal.GetLastWin32Error().ToString());
    1.12 @@ -101,7 +101,7 @@
    1.13          public static IntPtr GetPreParsedData(IntPtr hDevice)
    1.14          {
    1.15              uint ppDataSize = 256;
    1.16 -            int result = Win32.Function.GetRawInputDeviceInfoW(hDevice, Win32.Const.RIDI_PREPARSEDDATA, IntPtr.Zero, ref ppDataSize);
    1.17 +            int result = Win32.Function.GetRawInputDeviceInfo(hDevice, Win32.Const.RIDI_PREPARSEDDATA, IntPtr.Zero, ref ppDataSize);
    1.18              if (result != 0)
    1.19              {
    1.20                  Debug.WriteLine("Failed to get raw input pre-parsed data size" + result + Marshal.GetLastWin32Error());
    1.21 @@ -109,7 +109,7 @@
    1.22              }
    1.23  
    1.24              IntPtr ppData = Marshal.AllocHGlobal((int)ppDataSize);
    1.25 -            result = Win32.Function.GetRawInputDeviceInfoW(hDevice, Win32.Const.RIDI_PREPARSEDDATA, ppData, ref ppDataSize);
    1.26 +            result = Win32.Function.GetRawInputDeviceInfo(hDevice, Win32.Const.RIDI_PREPARSEDDATA, ppData, ref ppDataSize);
    1.27              if (result <= 0)
    1.28              {
    1.29                  Debug.WriteLine("Failed to get raw input pre-parsed data" + result + Marshal.GetLastWin32Error());
    1.30 @@ -126,7 +126,7 @@
    1.31          public static string GetDeviceName(IntPtr device)
    1.32          {
    1.33              uint deviceNameSize = 256;
    1.34 -            int result = Win32.Function.GetRawInputDeviceInfoW(device, Win32.Const.RIDI_DEVICENAME, IntPtr.Zero, ref deviceNameSize);
    1.35 +            int result = Win32.Function.GetRawInputDeviceInfo(device, Win32.Const.RIDI_DEVICENAME, IntPtr.Zero, ref deviceNameSize);
    1.36              if (result != 0)
    1.37              {
    1.38                  return string.Empty;
    1.39 @@ -135,10 +135,10 @@
    1.40              IntPtr deviceName = Marshal.AllocHGlobal((int)deviceNameSize * 2);  // size is the character count not byte count
    1.41              try
    1.42              {
    1.43 -                result = Win32.Function.GetRawInputDeviceInfoW(device, Win32.Const.RIDI_DEVICENAME, deviceName, ref deviceNameSize);
    1.44 +                result = Win32.Function.GetRawInputDeviceInfo(device, Win32.Const.RIDI_DEVICENAME, deviceName, ref deviceNameSize);
    1.45                  if (result > 0)
    1.46                  {
    1.47 -                    return Marshal.PtrToStringUni(deviceName, result - 1); // -1 for NULL termination
    1.48 +                    return Marshal.PtrToStringAnsi(deviceName, result - 1); // -1 for NULL termination
    1.49                  }
    1.50  
    1.51                  return string.Empty;
     2.1 --- a/RemoteControlDevice.cs	Sat Dec 06 02:46:46 2014 +0100
     2.2 +++ b/RemoteControlDevice.cs	Sat Dec 06 03:26:27 2014 +0100
     2.3 @@ -2,9 +2,12 @@
     2.4  using System.Windows.Forms;
     2.5  using System.Runtime.InteropServices;
     2.6  using System.Diagnostics;
     2.7 +using System.Text;
     2.8 +
     2.9  using Hid.UsageTables;
    2.10  using Win32;
    2.11  
    2.12 +
    2.13  namespace Devices.RemoteControl
    2.14  {
    2.15  
    2.16 @@ -392,6 +395,18 @@
    2.17                      return;
    2.18                  }
    2.19  
    2.20 +                /*
    2.21 +                //TODO: This needs create file from the device name/path
    2.22 +                //Get device manufacturer
    2.23 +                StringBuilder manufacturerString = new StringBuilder(256);
    2.24 +                bool returnStatus = Win32.Function.HidD_GetManufacturerString(rawInput.header.hDevice, manufacturerString, manufacturerString.Capacity);
    2.25 +                if (returnStatus)
    2.26 +                {
    2.27 +                    Debug.WriteLine("Manufacturer name is {0}", manufacturerString.ToString());
    2.28 +                }
    2.29 +                */
    2.30 +
    2.31 +
    2.32                  //Fetch device info
    2.33                  RID_DEVICE_INFO deviceInfo = new RID_DEVICE_INFO();
    2.34                  if (!RawInput.GetDeviceInfo(rawInput.header.hDevice, ref deviceInfo))
    2.35 @@ -499,7 +514,7 @@
    2.36                      Debug.WriteLine("Mode: " + deviceInfo.keyboard.dwKeyboardMode.ToString());
    2.37                      Debug.WriteLine("Number of function keys: " + deviceInfo.keyboard.dwNumberOfFunctionKeys.ToString());
    2.38                      Debug.WriteLine("Number of indicators: " + deviceInfo.keyboard.dwNumberOfIndicators.ToString());
    2.39 -                    Debug.WriteLine("Number of keys total: " + deviceInfo.keyboard.dwNumberOfKeysTotal.ToString());                   
    2.40 +                    Debug.WriteLine("Number of keys total: " + deviceInfo.keyboard.dwNumberOfKeysTotal.ToString());
    2.41                  }
    2.42              }
    2.43              finally
     3.1 --- a/Win32Hid.cs	Sat Dec 06 02:46:46 2014 +0100
     3.2 +++ b/Win32Hid.cs	Sat Dec 06 03:26:27 2014 +0100
     3.3 @@ -1,5 +1,7 @@
     3.4  using System;
     3.5  using System.Runtime.InteropServices;
     3.6 +using Microsoft.Win32.SafeHandles;
     3.7 +using System.Text;
     3.8  
     3.9  namespace Win32
    3.10  {
    3.11 @@ -8,6 +10,10 @@
    3.12      {
    3.13          [DllImport("hid.dll", CharSet = CharSet.Unicode)]
    3.14          public static extern HidStatus HidP_GetUsagesEx(HIDP_REPORT_TYPE ReportType, ushort LinkCollection, [Out, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 3)] USAGE_AND_PAGE[] ButtonList, ref uint UsageLength, IntPtr PreparsedData, [MarshalAs(UnmanagedType.LPArray)] byte[] Report, uint ReportLength);
    3.15 +
    3.16 +        [DllImport("hid.dll", CharSet = CharSet.Auto, SetLastError = true)]
    3.17 +        public static extern Boolean HidD_GetManufacturerString(/*SafeFileHandle*/ IntPtr HidDeviceObject, StringBuilder Buffer, Int32 BufferLength);
    3.18 +
    3.19      }
    3.20  
    3.21  
     4.1 --- a/Win32RawInput.cs	Sat Dec 06 02:46:46 2014 +0100
     4.2 +++ b/Win32RawInput.cs	Sat Dec 06 03:26:27 2014 +0100
     4.3 @@ -13,7 +13,7 @@
     4.4  		public extern static uint GetRawInputData(IntPtr hRawInput, uint uiCommand, IntPtr pData, ref uint pcbSize, uint cbSizeHeader);
     4.5  
     4.6     		[DllImport("User32.dll", SetLastError=true)]
     4.7 -		public extern static int GetRawInputDeviceInfoW(IntPtr hDevice, uint uiCommand, IntPtr pData, ref uint pcbSize);
     4.8 +		public extern static int GetRawInputDeviceInfo(IntPtr hDevice, uint uiCommand, IntPtr pData, ref uint pcbSize);
     4.9      }
    4.10  
    4.11