# HG changeset patch # User StephaneLenclud # Date 1423997616 -3600 # Node ID cace0afae0fa4c7b07977f1ab069a03e216f94d6 # Parent 08c70af8af84956d23bee33f1cd3738aee08abc4 HidDevice now supports capabilities and button capabilities. diff -r 08c70af8af84 -r cace0afae0fa HidDevice.cs --- a/HidDevice.cs Sun Feb 15 10:50:09 2015 +0100 +++ b/HidDevice.cs Sun Feb 15 11:53:36 2015 +0100 @@ -19,9 +19,18 @@ public ushort VendorId { get; private set; } public ushort ProductId { get; private set; } public ushort Version { get; private set; } + //Pre-parsed HID descriptor public IntPtr PreParsedData {get; private set;} + //Info public RID_DEVICE_INFO Info { get {return iInfo;} } private RID_DEVICE_INFO iInfo; + //Capabilities + public HIDP_CAPS Capabilities { get { return iCapabilities; } } + private HIDP_CAPS iCapabilities; + //Input Button Capabilities + public HIDP_BUTTON_CAPS[] InputButtonCapabilities { get { return iInputButtonCapabilities; } } + private HIDP_BUTTON_CAPS[] iInputButtonCapabilities; + /// /// Class constructor will fetch this object properties from HID sub system. @@ -115,6 +124,24 @@ } handle.Close(); + + //Get capabilities + HidStatus status = Win32.Function.HidP_GetCaps(PreParsedData, ref iCapabilities); + if (status != HidStatus.HIDP_STATUS_SUCCESS) + { + throw new Exception("HidDevice: HidP_GetCaps failed: " + status.ToString()); + } + + //Get input button caps + iInputButtonCapabilities = new HIDP_BUTTON_CAPS[Capabilities.NumberInputButtonCaps]; + ushort buttonCapabilitiesLength = Capabilities.NumberInputButtonCaps; + status = Win32.Function.HidP_GetButtonCaps(HIDP_REPORT_TYPE.HidP_Input, iInputButtonCapabilities, ref buttonCapabilitiesLength, PreParsedData); + if (status != HidStatus.HIDP_STATUS_SUCCESS || buttonCapabilitiesLength != Capabilities.NumberInputButtonCaps) + { + throw new Exception("HidDevice: HidP_GetButtonCaps failed: " + status.ToString()); + } + + } /// diff -r 08c70af8af84 -r cace0afae0fa Win32Hid.cs --- a/Win32Hid.cs Sun Feb 15 10:50:09 2015 +0100 +++ b/Win32Hid.cs Sun Feb 15 11:53:36 2015 +0100 @@ -24,23 +24,23 @@ ///PreparsedData: PHIDP_PREPARSED_DATA->_HIDP_PREPARSED_DATA* ///Capabilities: PHIDP_CAPS->_HIDP_CAPS* [DllImportAttribute("hid.dll", EntryPoint = "HidP_GetCaps", CallingConvention = CallingConvention.StdCall)] - public static extern int HidP_GetCaps(System.IntPtr PreparsedData, ref HIDP_CAPS Capabilities); + public static extern HidStatus HidP_GetCaps(System.IntPtr PreparsedData, ref HIDP_CAPS Capabilities); /// Return Type: NTSTATUS->LONG->int ///ReportType: HIDP_REPORT_TYPE->_HIDP_REPORT_TYPE ///ButtonCaps: PHIDP_BUTTON_CAPS->_HIDP_BUTTON_CAPS* ///ButtonCapsLength: PUSHORT->USHORT* ///PreparsedData: PHIDP_PREPARSED_DATA->_HIDP_PREPARSED_DATA* - [System.Runtime.InteropServices.DllImportAttribute("", EntryPoint = "HidP_GetButtonCaps", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)] - public static extern int HidP_GetButtonCaps(HIDP_REPORT_TYPE ReportType, ref HIDP_BUTTON_CAPS ButtonCaps, ref ushort ButtonCapsLength, System.IntPtr PreparsedData); + [System.Runtime.InteropServices.DllImportAttribute("hid.dll", EntryPoint = "HidP_GetButtonCaps", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)] + public static extern HidStatus HidP_GetButtonCaps(HIDP_REPORT_TYPE ReportType, [Out, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2)] HIDP_BUTTON_CAPS[] ButtonCaps, ref ushort ButtonCapsLength, System.IntPtr PreparsedData); /// Return Type: NTSTATUS->LONG->int ///ReportType: HIDP_REPORT_TYPE->_HIDP_REPORT_TYPE ///ValueCaps: PHIDP_VALUE_CAPS->_HIDP_VALUE_CAPS* ///ValueCapsLength: PUSHORT->USHORT* ///PreparsedData: PHIDP_PREPARSED_DATA->_HIDP_PREPARSED_DATA* - [System.Runtime.InteropServices.DllImportAttribute("", EntryPoint = "HidP_GetValueCaps", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)] - public static extern int HidP_GetValueCaps(HIDP_REPORT_TYPE ReportType, ref HIDP_VALUE_CAPS ValueCaps, ref ushort ValueCapsLength, System.IntPtr PreparsedData); + [System.Runtime.InteropServices.DllImportAttribute("hid.dll", EntryPoint = "HidP_GetValueCaps", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)] + public static extern HidStatus HidP_GetValueCaps(HIDP_REPORT_TYPE ReportType, ref HIDP_VALUE_CAPS[] ValueCaps, ref ushort ValueCapsLength, System.IntPtr PreparsedData); }