# HG changeset patch # User sl # Date 1417832787 -3600 # Node ID 743cadfacda084410139422839d74bc7a16f21d6 # Parent 8b2a3da541873e688b3be93430a0c5729e85babb Was trying to get manufacturer string. diff -r 8b2a3da54187 -r 743cadfacda0 RawInput.cs --- a/RawInput.cs Sat Dec 06 02:46:46 2014 +0100 +++ b/RawInput.cs Sat Dec 06 03:26:27 2014 +0100 @@ -68,7 +68,7 @@ uint deviceInfoSize = (uint)Marshal.SizeOf(typeof(RID_DEVICE_INFO)); deviceInfoBuffer = Marshal.AllocHGlobal((int)deviceInfoSize); - int res = Win32.Function.GetRawInputDeviceInfoW(hDevice, Const.RIDI_DEVICEINFO, deviceInfoBuffer, ref deviceInfoSize); + int res = Win32.Function.GetRawInputDeviceInfo(hDevice, Const.RIDI_DEVICEINFO, deviceInfoBuffer, ref deviceInfoSize); if (res <= 0) { Debug.WriteLine("WM_INPUT could not read device info: " + Marshal.GetLastWin32Error().ToString()); @@ -101,7 +101,7 @@ public static IntPtr GetPreParsedData(IntPtr hDevice) { uint ppDataSize = 256; - int result = Win32.Function.GetRawInputDeviceInfoW(hDevice, Win32.Const.RIDI_PREPARSEDDATA, IntPtr.Zero, ref ppDataSize); + int result = Win32.Function.GetRawInputDeviceInfo(hDevice, Win32.Const.RIDI_PREPARSEDDATA, IntPtr.Zero, ref ppDataSize); if (result != 0) { Debug.WriteLine("Failed to get raw input pre-parsed data size" + result + Marshal.GetLastWin32Error()); @@ -109,7 +109,7 @@ } IntPtr ppData = Marshal.AllocHGlobal((int)ppDataSize); - result = Win32.Function.GetRawInputDeviceInfoW(hDevice, Win32.Const.RIDI_PREPARSEDDATA, ppData, ref ppDataSize); + result = Win32.Function.GetRawInputDeviceInfo(hDevice, Win32.Const.RIDI_PREPARSEDDATA, ppData, ref ppDataSize); if (result <= 0) { Debug.WriteLine("Failed to get raw input pre-parsed data" + result + Marshal.GetLastWin32Error()); @@ -126,7 +126,7 @@ public static string GetDeviceName(IntPtr device) { uint deviceNameSize = 256; - int result = Win32.Function.GetRawInputDeviceInfoW(device, Win32.Const.RIDI_DEVICENAME, IntPtr.Zero, ref deviceNameSize); + int result = Win32.Function.GetRawInputDeviceInfo(device, Win32.Const.RIDI_DEVICENAME, IntPtr.Zero, ref deviceNameSize); if (result != 0) { return string.Empty; @@ -135,10 +135,10 @@ IntPtr deviceName = Marshal.AllocHGlobal((int)deviceNameSize * 2); // size is the character count not byte count try { - result = Win32.Function.GetRawInputDeviceInfoW(device, Win32.Const.RIDI_DEVICENAME, deviceName, ref deviceNameSize); + result = Win32.Function.GetRawInputDeviceInfo(device, Win32.Const.RIDI_DEVICENAME, deviceName, ref deviceNameSize); if (result > 0) { - return Marshal.PtrToStringUni(deviceName, result - 1); // -1 for NULL termination + return Marshal.PtrToStringAnsi(deviceName, result - 1); // -1 for NULL termination } return string.Empty; diff -r 8b2a3da54187 -r 743cadfacda0 RemoteControlDevice.cs --- a/RemoteControlDevice.cs Sat Dec 06 02:46:46 2014 +0100 +++ b/RemoteControlDevice.cs Sat Dec 06 03:26:27 2014 +0100 @@ -2,9 +2,12 @@ using System.Windows.Forms; using System.Runtime.InteropServices; using System.Diagnostics; +using System.Text; + using Hid.UsageTables; using Win32; + namespace Devices.RemoteControl { @@ -392,6 +395,18 @@ return; } + /* + //TODO: This needs create file from the device name/path + //Get device manufacturer + StringBuilder manufacturerString = new StringBuilder(256); + bool returnStatus = Win32.Function.HidD_GetManufacturerString(rawInput.header.hDevice, manufacturerString, manufacturerString.Capacity); + if (returnStatus) + { + Debug.WriteLine("Manufacturer name is {0}", manufacturerString.ToString()); + } + */ + + //Fetch device info RID_DEVICE_INFO deviceInfo = new RID_DEVICE_INFO(); if (!RawInput.GetDeviceInfo(rawInput.header.hDevice, ref deviceInfo)) @@ -499,7 +514,7 @@ Debug.WriteLine("Mode: " + deviceInfo.keyboard.dwKeyboardMode.ToString()); Debug.WriteLine("Number of function keys: " + deviceInfo.keyboard.dwNumberOfFunctionKeys.ToString()); Debug.WriteLine("Number of indicators: " + deviceInfo.keyboard.dwNumberOfIndicators.ToString()); - Debug.WriteLine("Number of keys total: " + deviceInfo.keyboard.dwNumberOfKeysTotal.ToString()); + Debug.WriteLine("Number of keys total: " + deviceInfo.keyboard.dwNumberOfKeysTotal.ToString()); } } finally diff -r 8b2a3da54187 -r 743cadfacda0 Win32Hid.cs --- a/Win32Hid.cs Sat Dec 06 02:46:46 2014 +0100 +++ b/Win32Hid.cs Sat Dec 06 03:26:27 2014 +0100 @@ -1,5 +1,7 @@ using System; using System.Runtime.InteropServices; +using Microsoft.Win32.SafeHandles; +using System.Text; namespace Win32 { @@ -8,6 +10,10 @@ { [DllImport("hid.dll", CharSet = CharSet.Unicode)] 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); + + [DllImport("hid.dll", CharSet = CharSet.Auto, SetLastError = true)] + public static extern Boolean HidD_GetManufacturerString(/*SafeFileHandle*/ IntPtr HidDeviceObject, StringBuilder Buffer, Int32 BufferLength); + } diff -r 8b2a3da54187 -r 743cadfacda0 Win32RawInput.cs --- a/Win32RawInput.cs Sat Dec 06 02:46:46 2014 +0100 +++ b/Win32RawInput.cs Sat Dec 06 03:26:27 2014 +0100 @@ -13,7 +13,7 @@ public extern static uint GetRawInputData(IntPtr hRawInput, uint uiCommand, IntPtr pData, ref uint pcbSize, uint cbSizeHeader); [DllImport("User32.dll", SetLastError=true)] - public extern static int GetRawInputDeviceInfoW(IntPtr hDevice, uint uiCommand, IntPtr pData, ref uint pcbSize); + public extern static int GetRawInputDeviceInfo(IntPtr hDevice, uint uiCommand, IntPtr pData, ref uint pcbSize); }