Win32Hid.cs
author sl
Sat, 06 Dec 2014 13:08:50 +0100
changeset 25 5f4e0fbb3ea1
parent 24 974f5fdaebfb
child 50 e6c103ebb155
permissions -rw-r--r--
Adding HidDevice class.
sl@17
     1
using System;
sl@17
     2
using System.Runtime.InteropServices;
sl@23
     3
using Microsoft.Win32.SafeHandles;
sl@23
     4
using System.Text;
sl@17
     5
sl@17
     6
namespace Win32
sl@17
     7
{
sl@17
     8
sl@17
     9
    static partial class Function
sl@17
    10
    {
sl@17
    11
        [DllImport("hid.dll", CharSet = CharSet.Unicode)]
sl@17
    12
        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
    13
sl@23
    14
        [DllImport("hid.dll", CharSet = CharSet.Auto, SetLastError = true)]
sl@24
    15
        public static extern Boolean HidD_GetManufacturerString(SafeFileHandle HidDeviceObject, StringBuilder Buffer, Int32 BufferLength);
sl@24
    16
sl@24
    17
        [DllImport("hid.dll", CharSet = CharSet.Auto, SetLastError = true)]
sl@24
    18
        public static extern Boolean HidD_GetProductString(SafeFileHandle HidDeviceObject, StringBuilder Buffer, Int32 BufferLength);
sl@23
    19
sl@25
    20
        [DllImport("hid.dll", CharSet = CharSet.Auto, SetLastError = true)]
sl@25
    21
        public static extern Boolean HidD_GetAttributes(SafeFileHandle HidDeviceObject, ref HIDD_ATTRIBUTES Attributes);
sl@17
    22
    }
sl@17
    23
sl@17
    24
sl@17
    25
    static partial class Macro
sl@17
    26
    {
sl@17
    27
sl@17
    28
sl@17
    29
    }
sl@17
    30
sl@17
    31
sl@17
    32
    static partial class Const
sl@17
    33
    {
sl@17
    34
sl@17
    35
sl@17
    36
    }
sl@17
    37
sl@17
    38
sl@17
    39
    public enum HIDP_REPORT_TYPE : ushort
sl@17
    40
    {
sl@17
    41
        HidP_Input = 0,
sl@17
    42
        HidP_Output,
sl@17
    43
        HidP_Feature
sl@17
    44
    }
sl@17
    45
sl@17
    46
sl@17
    47
    public enum HidStatus : uint
sl@17
    48
    {
sl@17
    49
        HIDP_STATUS_SUCCESS = 0x110000,
sl@17
    50
        HIDP_STATUS_NULL = 0x80110001,
sl@17
    51
        HIDP_STATUS_INVALID_PREPARSED_DATA = 0xc0110001,
sl@17
    52
        HIDP_STATUS_INVALID_REPORT_TYPE = 0xc0110002,
sl@17
    53
        HIDP_STATUS_INVALID_REPORT_LENGTH = 0xc0110003,
sl@17
    54
        HIDP_STATUS_USAGE_NOT_FOUND = 0xc0110004,
sl@17
    55
        HIDP_STATUS_VALUE_OUT_OF_RANGE = 0xc0110005,
sl@17
    56
        HIDP_STATUS_BAD_LOG_PHY_VALUES = 0xc0110006,
sl@17
    57
        HIDP_STATUS_BUFFER_TOO_SMALL = 0xc0110007,
sl@17
    58
        HIDP_STATUS_INTERNAL_ERROR = 0xc0110008,
sl@17
    59
        HIDP_STATUS_I8042_TRANS_UNKNOWN = 0xc0110009,
sl@17
    60
        HIDP_STATUS_INCOMPATIBLE_REPORT_ID = 0xc011000a,
sl@17
    61
        HIDP_STATUS_NOT_VALUE_ARRAY = 0xc011000b,
sl@17
    62
        HIDP_STATUS_IS_VALUE_ARRAY = 0xc011000c,
sl@17
    63
        HIDP_STATUS_DATA_INDEX_NOT_FOUND = 0xc011000d,
sl@17
    64
        HIDP_STATUS_DATA_INDEX_OUT_OF_RANGE = 0xc011000e,
sl@17
    65
        HIDP_STATUS_BUTTON_NOT_PRESSED = 0xc011000f,
sl@17
    66
        HIDP_STATUS_REPORT_DOES_NOT_EXIST = 0xc0110010,
sl@17
    67
        HIDP_STATUS_NOT_IMPLEMENTED = 0xc0110020,
sl@17
    68
        HIDP_STATUS_I8242_TRANS_UNKNOWN = 0xc0110009
sl@17
    69
    }
sl@17
    70
sl@17
    71
sl@17
    72
    [StructLayout(LayoutKind.Sequential)]
sl@17
    73
    public struct USAGE_AND_PAGE
sl@17
    74
    {
sl@17
    75
        public ushort Usage;
sl@17
    76
        public ushort UsagePage;
sl@17
    77
    };
sl@17
    78
sl@25
    79
    [StructLayout(LayoutKind.Sequential)]
sl@25
    80
    public struct HIDD_ATTRIBUTES
sl@25
    81
    {
sl@25
    82
        public uint Size;
sl@25
    83
        public ushort VendorID;
sl@25
    84
        public ushort ProductID;
sl@25
    85
        public ushort VersionNumber;
sl@25
    86
    }
sl@25
    87
sl@17
    88
sl@17
    89
}