Win32Hid: improved button caps structure.
authorStephaneLenclud
Sun, 15 Feb 2015 12:10:40 +0100
changeset 57878e0b271c11
parent 56 cace0afae0fa
child 58 7ef0f9dc229c
Win32Hid: improved button caps structure.
Win32Hid.cs
     1.1 --- a/Win32Hid.cs	Sun Feb 15 11:53:36 2015 +0100
     1.2 +++ b/Win32Hid.cs	Sun Feb 15 12:10:40 2015 +0100
     1.3 @@ -227,62 +227,67 @@
     1.4          public ushort Reserved4;
     1.5      }
     1.6  
     1.7 -    [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Explicit)]
     1.8 -    public struct HIDP_BUTTON_CAPS_UNION
     1.9 -    {
    1.10 -
    1.11 -        /// 
    1.12 -        [System.Runtime.InteropServices.FieldOffsetAttribute(0)]
    1.13 -        public HIDP_BUTTON_CAPS_RANGE Range;
    1.14 -
    1.15 -        /// 
    1.16 -        [System.Runtime.InteropServices.FieldOffsetAttribute(0)]
    1.17 -        public HIDP_BUTTON_CAPS_NOT_RANGE NotRange;
    1.18 -    }
    1.19 -
    1.20 -    [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
    1.21 +    /// <summary>
    1.22 +    /// 
    1.23 +    /// </summary>
    1.24 +    [StructLayoutAttribute(LayoutKind.Explicit, Pack = 1)]
    1.25      public struct HIDP_BUTTON_CAPS
    1.26      {
    1.27 -
    1.28          /// USAGE->USHORT->unsigned short
    1.29 +        [FieldOffset(0)]
    1.30          public ushort UsagePage;
    1.31  
    1.32          /// UCHAR->unsigned char
    1.33 +        [FieldOffset(2)]
    1.34          public byte ReportID;
    1.35  
    1.36          /// BOOLEAN->BYTE->unsigned char
    1.37 -        public byte IsAlias;
    1.38 +        [FieldOffset(3)]
    1.39 +        public bool IsAlias;
    1.40  
    1.41          /// USHORT->unsigned short
    1.42 +        [FieldOffset(4)]
    1.43          public ushort BitField;
    1.44  
    1.45          /// USHORT->unsigned short
    1.46 +        [FieldOffset(6)]
    1.47          public ushort LinkCollection;
    1.48  
    1.49          /// USAGE->USHORT->unsigned short
    1.50 +        [FieldOffset(8)]
    1.51          public ushort LinkUsage;
    1.52  
    1.53          /// USAGE->USHORT->unsigned short
    1.54 +        [FieldOffset(10)]
    1.55          public ushort LinkUsagePage;
    1.56  
    1.57          /// BOOLEAN->BYTE->unsigned char
    1.58 -        public byte IsRange;
    1.59 +        [FieldOffset(12)]
    1.60 +        public bool IsRange;
    1.61  
    1.62          /// BOOLEAN->BYTE->unsigned char
    1.63 -        public byte IsStringRange;
    1.64 +        [FieldOffset(13)]
    1.65 +        public bool IsStringRange;
    1.66  
    1.67          /// BOOLEAN->BYTE->unsigned char
    1.68 -        public byte IsDesignatorRange;
    1.69 +        [FieldOffset(14)]
    1.70 +        public bool IsDesignatorRange;
    1.71  
    1.72          /// BOOLEAN->BYTE->unsigned char
    1.73 -        public byte IsAbsolute;
    1.74 +        [FieldOffset(15)]
    1.75 +        public bool IsAbsolute;
    1.76  
    1.77          /// ULONG[10]
    1.78 -        [System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst = 10, ArraySubType = System.Runtime.InteropServices.UnmanagedType.U4)]
    1.79 +        [FieldOffset(16)]
    1.80 +        [MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 10, ArraySubType = UnmanagedType.U4)]
    1.81          public uint[] Reserved;
    1.82  
    1.83 -        /// TODO: get the proper field offset to make it nicer and get rid of union type
    1.84 -        public HIDP_BUTTON_CAPS_UNION Union;
    1.85 +        /// Union Range/NotRange
    1.86 +        [FieldOffset(56)]
    1.87 +        HIDP_BUTTON_CAPS_RANGE Range;
    1.88 +
    1.89 +        [FieldOffset(56)]
    1.90 +        HIDP_BUTTON_CAPS_NOT_RANGE NotRange;       
    1.91      }
    1.92  
    1.93      /// <summary>