RemoteControlDevice.cs
changeset 24 974f5fdaebfb
parent 23 743cadfacda0
child 25 5f4e0fbb3ea1
     1.1 --- a/RemoteControlDevice.cs	Sat Dec 06 03:26:27 2014 +0100
     1.2 +++ b/RemoteControlDevice.cs	Sat Dec 06 12:13:39 2014 +0100
     1.3 @@ -3,11 +3,13 @@
     1.4  using System.Runtime.InteropServices;
     1.5  using System.Diagnostics;
     1.6  using System.Text;
     1.7 +using Microsoft.Win32.SafeHandles;
     1.8  
     1.9  using Hid.UsageTables;
    1.10  using Win32;
    1.11  
    1.12  
    1.13 +
    1.14  namespace Devices.RemoteControl
    1.15  {
    1.16  
    1.17 @@ -395,16 +397,6 @@
    1.18                      return;
    1.19                  }
    1.20  
    1.21 -                /*
    1.22 -                //TODO: This needs create file from the device name/path
    1.23 -                //Get device manufacturer
    1.24 -                StringBuilder manufacturerString = new StringBuilder(256);
    1.25 -                bool returnStatus = Win32.Function.HidD_GetManufacturerString(rawInput.header.hDevice, manufacturerString, manufacturerString.Capacity);
    1.26 -                if (returnStatus)
    1.27 -                {
    1.28 -                    Debug.WriteLine("Manufacturer name is {0}", manufacturerString.ToString());
    1.29 -                }
    1.30 -                */
    1.31  
    1.32  
    1.33                  //Fetch device info
    1.34 @@ -414,10 +406,48 @@
    1.35                      return;
    1.36                  }
    1.37  
    1.38 -                //
    1.39 -                Debug.WriteLine(RawInput.GetDeviceName(rawInput.header.hDevice));
    1.40 +                //Debug
    1.41 +                string deviceName = RawInput.GetDeviceName(rawInput.header.hDevice);
    1.42 +                Debug.WriteLine("Device name: " + deviceName);
    1.43 +                
    1.44 +                //Open our device from the device name/path
    1.45 +                SafeFileHandle handle=Win32.Function.CreateFile(deviceName,
    1.46 +                    Win32.FileAccess.NONE,
    1.47 +                    Win32.FileShare.FILE_SHARE_READ|Win32.FileShare.FILE_SHARE_WRITE,
    1.48 +                    IntPtr.Zero,
    1.49 +                    Win32.CreationDisposition.OPEN_EXISTING,
    1.50 +                    Win32.FileFlagsAttributes.FILE_FLAG_OVERLAPPED,
    1.51 +                    IntPtr.Zero
    1.52 +                    );
    1.53 +
    1.54 +                if (handle.IsInvalid)
    1.55 +                {
    1.56 +                    Debug.WriteLine("Failed to CreateFile from device name " + Marshal.GetLastWin32Error().ToString());
    1.57 +                }
    1.58 +                else
    1.59 +                {
    1.60 +                    //Get manufacturer string
    1.61 +                    StringBuilder manufacturerString = new StringBuilder(256);
    1.62 +                    bool returnStatus = Win32.Function.HidD_GetManufacturerString(handle, manufacturerString, manufacturerString.Capacity);
    1.63 +                    if (returnStatus)
    1.64 +                    {
    1.65 +                        Debug.WriteLine("Manufacturer: " + manufacturerString.ToString());
    1.66 +                    }
    1.67 +
    1.68 +                    //Get product string
    1.69 +                    StringBuilder productString = new StringBuilder(256);
    1.70 +                    returnStatus = Win32.Function.HidD_GetProductString(handle, productString, productString.Capacity);
    1.71 +                    if (returnStatus)
    1.72 +                    {
    1.73 +                        Debug.WriteLine("Product: " + productString.ToString());
    1.74 +                    }
    1.75 +
    1.76 +                    handle.Close();
    1.77 +
    1.78 +                }
    1.79                 
    1.80  
    1.81 +
    1.82                  if (rawInput.header.dwType == Const.RIM_TYPEHID)  //Check that our raw input is HID                        
    1.83                  {
    1.84                      Debug.WriteLine("WM_INPUT source device is HID.");