sl@17: using System; sl@17: using System.Runtime.InteropServices; sl@23: using Microsoft.Win32.SafeHandles; sl@23: using System.Text; sl@17: sl@17: namespace Win32 sl@17: { sl@17: sl@17: static partial class Function sl@17: { sl@17: [DllImport("hid.dll", CharSet = CharSet.Unicode)] sl@17: 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); sl@23: sl@23: [DllImport("hid.dll", CharSet = CharSet.Auto, SetLastError = true)] sl@24: public static extern Boolean HidD_GetManufacturerString(SafeFileHandle HidDeviceObject, StringBuilder Buffer, Int32 BufferLength); sl@24: sl@24: [DllImport("hid.dll", CharSet = CharSet.Auto, SetLastError = true)] sl@24: public static extern Boolean HidD_GetProductString(SafeFileHandle HidDeviceObject, StringBuilder Buffer, Int32 BufferLength); sl@23: sl@25: [DllImport("hid.dll", CharSet = CharSet.Auto, SetLastError = true)] sl@25: public static extern Boolean HidD_GetAttributes(SafeFileHandle HidDeviceObject, ref HIDD_ATTRIBUTES Attributes); StephaneLenclud@50: StephaneLenclud@51: /// Return Type: NTSTATUS->LONG->int StephaneLenclud@51: ///PreparsedData: PHIDP_PREPARSED_DATA->_HIDP_PREPARSED_DATA* StephaneLenclud@51: ///Capabilities: PHIDP_CAPS->_HIDP_CAPS* StephaneLenclud@51: [DllImportAttribute("hid.dll", EntryPoint = "HidP_GetCaps", CallingConvention = CallingConvention.StdCall)] StephaneLenclud@56: public static extern HidStatus HidP_GetCaps(System.IntPtr PreparsedData, ref HIDP_CAPS Capabilities); StephaneLenclud@50: StephaneLenclud@51: /// Return Type: NTSTATUS->LONG->int StephaneLenclud@51: ///ReportType: HIDP_REPORT_TYPE->_HIDP_REPORT_TYPE StephaneLenclud@51: ///ButtonCaps: PHIDP_BUTTON_CAPS->_HIDP_BUTTON_CAPS* StephaneLenclud@51: ///ButtonCapsLength: PUSHORT->USHORT* StephaneLenclud@51: ///PreparsedData: PHIDP_PREPARSED_DATA->_HIDP_PREPARSED_DATA* StephaneLenclud@56: [System.Runtime.InteropServices.DllImportAttribute("hid.dll", EntryPoint = "HidP_GetButtonCaps", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)] StephaneLenclud@56: 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); StephaneLenclud@50: StephaneLenclud@51: /// Return Type: NTSTATUS->LONG->int StephaneLenclud@51: ///ReportType: HIDP_REPORT_TYPE->_HIDP_REPORT_TYPE StephaneLenclud@51: ///ValueCaps: PHIDP_VALUE_CAPS->_HIDP_VALUE_CAPS* StephaneLenclud@51: ///ValueCapsLength: PUSHORT->USHORT* StephaneLenclud@51: ///PreparsedData: PHIDP_PREPARSED_DATA->_HIDP_PREPARSED_DATA* StephaneLenclud@56: [System.Runtime.InteropServices.DllImportAttribute("hid.dll", EntryPoint = "HidP_GetValueCaps", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)] StephaneLenclud@56: public static extern HidStatus HidP_GetValueCaps(HIDP_REPORT_TYPE ReportType, ref HIDP_VALUE_CAPS[] ValueCaps, ref ushort ValueCapsLength, System.IntPtr PreparsedData); StephaneLenclud@50: sl@17: } sl@17: sl@17: sl@17: static partial class Macro sl@17: { sl@17: sl@17: sl@17: } sl@17: sl@17: sl@17: static partial class Const sl@17: { sl@17: sl@17: sl@17: } sl@17: sl@17: sl@17: public enum HIDP_REPORT_TYPE : ushort sl@17: { sl@17: HidP_Input = 0, sl@17: HidP_Output, sl@17: HidP_Feature sl@17: } sl@17: sl@17: sl@17: public enum HidStatus : uint sl@17: { sl@17: HIDP_STATUS_SUCCESS = 0x110000, sl@17: HIDP_STATUS_NULL = 0x80110001, sl@17: HIDP_STATUS_INVALID_PREPARSED_DATA = 0xc0110001, sl@17: HIDP_STATUS_INVALID_REPORT_TYPE = 0xc0110002, sl@17: HIDP_STATUS_INVALID_REPORT_LENGTH = 0xc0110003, sl@17: HIDP_STATUS_USAGE_NOT_FOUND = 0xc0110004, sl@17: HIDP_STATUS_VALUE_OUT_OF_RANGE = 0xc0110005, sl@17: HIDP_STATUS_BAD_LOG_PHY_VALUES = 0xc0110006, sl@17: HIDP_STATUS_BUFFER_TOO_SMALL = 0xc0110007, sl@17: HIDP_STATUS_INTERNAL_ERROR = 0xc0110008, sl@17: HIDP_STATUS_I8042_TRANS_UNKNOWN = 0xc0110009, sl@17: HIDP_STATUS_INCOMPATIBLE_REPORT_ID = 0xc011000a, sl@17: HIDP_STATUS_NOT_VALUE_ARRAY = 0xc011000b, sl@17: HIDP_STATUS_IS_VALUE_ARRAY = 0xc011000c, sl@17: HIDP_STATUS_DATA_INDEX_NOT_FOUND = 0xc011000d, sl@17: HIDP_STATUS_DATA_INDEX_OUT_OF_RANGE = 0xc011000e, sl@17: HIDP_STATUS_BUTTON_NOT_PRESSED = 0xc011000f, sl@17: HIDP_STATUS_REPORT_DOES_NOT_EXIST = 0xc0110010, sl@17: HIDP_STATUS_NOT_IMPLEMENTED = 0xc0110020, sl@17: HIDP_STATUS_I8242_TRANS_UNKNOWN = 0xc0110009 sl@17: } sl@17: sl@17: sl@17: [StructLayout(LayoutKind.Sequential)] sl@17: public struct USAGE_AND_PAGE sl@17: { sl@17: public ushort Usage; sl@17: public ushort UsagePage; sl@17: }; sl@17: sl@25: [StructLayout(LayoutKind.Sequential)] sl@25: public struct HIDD_ATTRIBUTES sl@25: { sl@25: public uint Size; sl@25: public ushort VendorID; sl@25: public ushort ProductID; sl@25: public ushort VersionNumber; sl@25: } sl@25: sl@17: StephaneLenclud@51: [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] StephaneLenclud@51: public struct HIDP_CAPS StephaneLenclud@51: { StephaneLenclud@50: StephaneLenclud@51: /// USAGE->USHORT->unsigned short StephaneLenclud@51: public ushort Usage; StephaneLenclud@50: StephaneLenclud@51: /// USAGE->USHORT->unsigned short StephaneLenclud@51: public ushort UsagePage; StephaneLenclud@50: StephaneLenclud@51: /// USHORT->unsigned short StephaneLenclud@51: public ushort InputReportByteLength; StephaneLenclud@50: StephaneLenclud@51: /// USHORT->unsigned short StephaneLenclud@51: public ushort OutputReportByteLength; StephaneLenclud@50: StephaneLenclud@51: /// USHORT->unsigned short StephaneLenclud@51: public ushort FeatureReportByteLength; StephaneLenclud@50: StephaneLenclud@51: /// USHORT[17] StephaneLenclud@51: [System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst = 17, ArraySubType = System.Runtime.InteropServices.UnmanagedType.U2)] StephaneLenclud@51: public ushort[] Reserved; StephaneLenclud@50: StephaneLenclud@51: /// USHORT->unsigned short StephaneLenclud@51: public ushort NumberLinkCollectionNodes; StephaneLenclud@50: StephaneLenclud@51: /// USHORT->unsigned short StephaneLenclud@51: public ushort NumberInputButtonCaps; StephaneLenclud@50: StephaneLenclud@51: /// USHORT->unsigned short StephaneLenclud@51: public ushort NumberInputValueCaps; StephaneLenclud@50: StephaneLenclud@51: /// USHORT->unsigned short StephaneLenclud@51: public ushort NumberInputDataIndices; StephaneLenclud@50: StephaneLenclud@51: /// USHORT->unsigned short StephaneLenclud@51: public ushort NumberOutputButtonCaps; StephaneLenclud@50: StephaneLenclud@51: /// USHORT->unsigned short StephaneLenclud@51: public ushort NumberOutputValueCaps; StephaneLenclud@50: StephaneLenclud@51: /// USHORT->unsigned short StephaneLenclud@51: public ushort NumberOutputDataIndices; StephaneLenclud@50: StephaneLenclud@51: /// USHORT->unsigned short StephaneLenclud@51: public ushort NumberFeatureButtonCaps; StephaneLenclud@50: StephaneLenclud@51: /// USHORT->unsigned short StephaneLenclud@51: public ushort NumberFeatureValueCaps; StephaneLenclud@50: StephaneLenclud@51: /// USHORT->unsigned short StephaneLenclud@51: public ushort NumberFeatureDataIndices; StephaneLenclud@51: } StephaneLenclud@50: StephaneLenclud@51: /// StephaneLenclud@51: /// Type created in place of an anonymous struct StephaneLenclud@51: /// StephaneLenclud@51: [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] StephaneLenclud@51: public struct HIDP_BUTTON_CAPS_RANGE StephaneLenclud@51: { StephaneLenclud@50: StephaneLenclud@51: /// USAGE->USHORT->unsigned short StephaneLenclud@51: public ushort UsageMin; StephaneLenclud@50: StephaneLenclud@51: /// USAGE->USHORT->unsigned short StephaneLenclud@51: public ushort UsageMax; StephaneLenclud@50: StephaneLenclud@51: /// USHORT->unsigned short StephaneLenclud@51: public ushort StringMin; StephaneLenclud@50: StephaneLenclud@51: /// USHORT->unsigned short StephaneLenclud@51: public ushort StringMax; StephaneLenclud@50: StephaneLenclud@51: /// USHORT->unsigned short StephaneLenclud@51: public ushort DesignatorMin; StephaneLenclud@50: StephaneLenclud@51: /// USHORT->unsigned short StephaneLenclud@51: public ushort DesignatorMax; StephaneLenclud@50: StephaneLenclud@51: /// USHORT->unsigned short StephaneLenclud@51: public ushort DataIndexMin; StephaneLenclud@50: StephaneLenclud@51: /// USHORT->unsigned short StephaneLenclud@51: public ushort DataIndexMax; StephaneLenclud@51: } StephaneLenclud@50: StephaneLenclud@51: /// StephaneLenclud@51: /// Type created in place of an anonymous struct StephaneLenclud@51: /// StephaneLenclud@51: [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] StephaneLenclud@51: public struct HIDP_BUTTON_CAPS_NOT_RANGE StephaneLenclud@51: { StephaneLenclud@50: StephaneLenclud@51: /// USAGE->USHORT->unsigned short StephaneLenclud@51: public ushort Usage; StephaneLenclud@50: StephaneLenclud@51: /// USAGE->USHORT->unsigned short StephaneLenclud@51: public ushort Reserved1; StephaneLenclud@50: StephaneLenclud@51: /// USHORT->unsigned short StephaneLenclud@51: public ushort StringIndex; StephaneLenclud@50: StephaneLenclud@51: /// USHORT->unsigned short StephaneLenclud@51: public ushort Reserved2; StephaneLenclud@50: StephaneLenclud@51: /// USHORT->unsigned short StephaneLenclud@51: public ushort DesignatorIndex; StephaneLenclud@50: StephaneLenclud@51: /// USHORT->unsigned short StephaneLenclud@51: public ushort Reserved3; StephaneLenclud@50: StephaneLenclud@51: /// USHORT->unsigned short StephaneLenclud@51: public ushort DataIndex; StephaneLenclud@50: StephaneLenclud@51: /// USHORT->unsigned short StephaneLenclud@51: public ushort Reserved4; StephaneLenclud@51: } StephaneLenclud@50: StephaneLenclud@57: /// StephaneLenclud@57: /// StephaneLenclud@57: /// StephaneLenclud@57: [StructLayoutAttribute(LayoutKind.Explicit, Pack = 1)] StephaneLenclud@51: public struct HIDP_BUTTON_CAPS StephaneLenclud@51: { StephaneLenclud@51: /// USAGE->USHORT->unsigned short StephaneLenclud@57: [FieldOffset(0)] StephaneLenclud@51: public ushort UsagePage; StephaneLenclud@50: StephaneLenclud@51: /// UCHAR->unsigned char StephaneLenclud@57: [FieldOffset(2)] StephaneLenclud@51: public byte ReportID; StephaneLenclud@50: StephaneLenclud@51: /// BOOLEAN->BYTE->unsigned char StephaneLenclud@57: [FieldOffset(3)] StephaneLenclud@57: public bool IsAlias; StephaneLenclud@50: StephaneLenclud@51: /// USHORT->unsigned short StephaneLenclud@57: [FieldOffset(4)] StephaneLenclud@51: public ushort BitField; StephaneLenclud@50: StephaneLenclud@51: /// USHORT->unsigned short StephaneLenclud@57: [FieldOffset(6)] StephaneLenclud@51: public ushort LinkCollection; StephaneLenclud@50: StephaneLenclud@51: /// USAGE->USHORT->unsigned short StephaneLenclud@57: [FieldOffset(8)] StephaneLenclud@51: public ushort LinkUsage; StephaneLenclud@50: StephaneLenclud@51: /// USAGE->USHORT->unsigned short StephaneLenclud@57: [FieldOffset(10)] StephaneLenclud@51: public ushort LinkUsagePage; StephaneLenclud@50: StephaneLenclud@51: /// BOOLEAN->BYTE->unsigned char StephaneLenclud@57: [FieldOffset(12)] StephaneLenclud@57: public bool IsRange; StephaneLenclud@50: StephaneLenclud@51: /// BOOLEAN->BYTE->unsigned char StephaneLenclud@57: [FieldOffset(13)] StephaneLenclud@57: public bool IsStringRange; StephaneLenclud@50: StephaneLenclud@51: /// BOOLEAN->BYTE->unsigned char StephaneLenclud@57: [FieldOffset(14)] StephaneLenclud@57: public bool IsDesignatorRange; StephaneLenclud@50: StephaneLenclud@51: /// BOOLEAN->BYTE->unsigned char StephaneLenclud@57: [FieldOffset(15)] StephaneLenclud@57: public bool IsAbsolute; StephaneLenclud@50: StephaneLenclud@51: /// ULONG[10] StephaneLenclud@57: [FieldOffset(16)] StephaneLenclud@57: [MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 10, ArraySubType = UnmanagedType.U4)] StephaneLenclud@51: public uint[] Reserved; StephaneLenclud@50: StephaneLenclud@57: /// Union Range/NotRange StephaneLenclud@57: [FieldOffset(56)] StephaneLenclud@57: HIDP_BUTTON_CAPS_RANGE Range; StephaneLenclud@57: StephaneLenclud@57: [FieldOffset(56)] StephaneLenclud@57: HIDP_BUTTON_CAPS_NOT_RANGE NotRange; StephaneLenclud@51: } StephaneLenclud@50: StephaneLenclud@51: /// StephaneLenclud@51: /// Type created in place of an anonymous struct StephaneLenclud@51: /// StephaneLenclud@51: [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] StephaneLenclud@51: public struct HIDP_VALUE_CAPS_RANGE StephaneLenclud@51: { StephaneLenclud@50: StephaneLenclud@51: /// USAGE->USHORT->unsigned short StephaneLenclud@51: public ushort UsageMin; StephaneLenclud@50: StephaneLenclud@51: /// USAGE->USHORT->unsigned short StephaneLenclud@51: public ushort UsageMax; StephaneLenclud@50: StephaneLenclud@51: /// USHORT->unsigned short StephaneLenclud@51: public ushort StringMin; StephaneLenclud@50: StephaneLenclud@51: /// USHORT->unsigned short StephaneLenclud@51: public ushort StringMax; StephaneLenclud@50: StephaneLenclud@51: /// USHORT->unsigned short StephaneLenclud@51: public ushort DesignatorMin; StephaneLenclud@50: StephaneLenclud@51: /// USHORT->unsigned short StephaneLenclud@51: public ushort DesignatorMax; StephaneLenclud@50: StephaneLenclud@51: /// USHORT->unsigned short StephaneLenclud@51: public ushort DataIndexMin; StephaneLenclud@50: StephaneLenclud@51: /// USHORT->unsigned short StephaneLenclud@51: public ushort DataIndexMax; StephaneLenclud@51: } StephaneLenclud@50: StephaneLenclud@51: /// StephaneLenclud@51: /// Type created in place of an anonymous struct StephaneLenclud@51: /// StephaneLenclud@51: [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] StephaneLenclud@51: public struct HIDP_VALUE_CAPS_NOT_RANGE StephaneLenclud@51: { StephaneLenclud@50: StephaneLenclud@51: /// USAGE->USHORT->unsigned short StephaneLenclud@51: public ushort Usage; StephaneLenclud@50: StephaneLenclud@51: /// USAGE->USHORT->unsigned short StephaneLenclud@51: public ushort Reserved1; StephaneLenclud@50: StephaneLenclud@51: /// USHORT->unsigned short StephaneLenclud@51: public ushort StringIndex; StephaneLenclud@50: StephaneLenclud@51: /// USHORT->unsigned short StephaneLenclud@51: public ushort Reserved2; StephaneLenclud@50: StephaneLenclud@51: /// USHORT->unsigned short StephaneLenclud@51: public ushort DesignatorIndex; StephaneLenclud@50: StephaneLenclud@51: /// USHORT->unsigned short StephaneLenclud@51: public ushort Reserved3; StephaneLenclud@50: StephaneLenclud@51: /// USHORT->unsigned short StephaneLenclud@51: public ushort DataIndex; StephaneLenclud@50: StephaneLenclud@51: /// USHORT->unsigned short StephaneLenclud@51: public ushort Reserved4; StephaneLenclud@51: } StephaneLenclud@50: StephaneLenclud@51: [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Explicit)] StephaneLenclud@51: public struct HIDP_VALUE_CAPS_UNION StephaneLenclud@51: { StephaneLenclud@50: StephaneLenclud@51: /// StephaneLenclud@51: [System.Runtime.InteropServices.FieldOffsetAttribute(0)] StephaneLenclud@51: public HIDP_VALUE_CAPS_RANGE Range; StephaneLenclud@50: StephaneLenclud@51: /// StephaneLenclud@51: [System.Runtime.InteropServices.FieldOffsetAttribute(0)] StephaneLenclud@51: public HIDP_VALUE_CAPS_NOT_RANGE NotRange; StephaneLenclud@51: } StephaneLenclud@50: StephaneLenclud@51: [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] StephaneLenclud@51: public struct HIDP_VALUE_CAPS StephaneLenclud@51: { StephaneLenclud@50: StephaneLenclud@51: /// USAGE->USHORT->unsigned short StephaneLenclud@51: public ushort UsagePage; StephaneLenclud@50: StephaneLenclud@51: /// UCHAR->unsigned char StephaneLenclud@51: public byte ReportID; StephaneLenclud@50: StephaneLenclud@51: /// BOOLEAN->BYTE->unsigned char StephaneLenclud@51: public byte IsAlias; StephaneLenclud@50: StephaneLenclud@51: /// USHORT->unsigned short StephaneLenclud@51: public ushort BitField; StephaneLenclud@50: StephaneLenclud@51: /// USHORT->unsigned short StephaneLenclud@51: public ushort LinkCollection; StephaneLenclud@50: StephaneLenclud@51: /// USAGE->USHORT->unsigned short StephaneLenclud@51: public ushort LinkUsage; StephaneLenclud@50: StephaneLenclud@51: /// USAGE->USHORT->unsigned short StephaneLenclud@51: public ushort LinkUsagePage; StephaneLenclud@50: StephaneLenclud@51: /// BOOLEAN->BYTE->unsigned char StephaneLenclud@51: public byte IsRange; StephaneLenclud@50: StephaneLenclud@51: /// BOOLEAN->BYTE->unsigned char StephaneLenclud@51: public byte IsStringRange; StephaneLenclud@50: StephaneLenclud@51: /// BOOLEAN->BYTE->unsigned char StephaneLenclud@51: public byte IsDesignatorRange; StephaneLenclud@50: StephaneLenclud@51: /// BOOLEAN->BYTE->unsigned char StephaneLenclud@51: public byte IsAbsolute; StephaneLenclud@50: StephaneLenclud@51: /// BOOLEAN->BYTE->unsigned char StephaneLenclud@51: public byte HasNull; StephaneLenclud@50: StephaneLenclud@51: /// UCHAR->unsigned char StephaneLenclud@51: public byte Reserved; StephaneLenclud@50: StephaneLenclud@51: /// USHORT->unsigned short StephaneLenclud@51: public ushort BitSize; StephaneLenclud@50: StephaneLenclud@51: /// USHORT->unsigned short StephaneLenclud@51: public ushort ReportCount; StephaneLenclud@50: StephaneLenclud@51: /// USHORT[5] StephaneLenclud@51: [System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst = 5, ArraySubType = System.Runtime.InteropServices.UnmanagedType.U2)] StephaneLenclud@51: public ushort[] Reserved2; StephaneLenclud@50: StephaneLenclud@51: /// ULONG->unsigned int StephaneLenclud@51: public uint UnitsExp; StephaneLenclud@50: StephaneLenclud@51: /// ULONG->unsigned int StephaneLenclud@51: public uint Units; StephaneLenclud@50: StephaneLenclud@51: /// LONG->int StephaneLenclud@51: public int LogicalMin; StephaneLenclud@50: StephaneLenclud@51: /// LONG->int StephaneLenclud@51: public int LogicalMax; StephaneLenclud@50: StephaneLenclud@51: /// LONG->int StephaneLenclud@51: public int PhysicalMin; StephaneLenclud@50: StephaneLenclud@51: /// LONG->int StephaneLenclud@51: public int PhysicalMax; StephaneLenclud@50: StephaneLenclud@51: /// StephaneLenclud@51: public HIDP_VALUE_CAPS_UNION Union; StephaneLenclud@51: } StephaneLenclud@51: } StephaneLenclud@50: StephaneLenclud@51: