Win32Hid.cs
author sl
Sat, 06 Dec 2014 03:26:27 +0100
changeset 23 743cadfacda0
parent 17 8f7e35c3bfd1
child 24 974f5fdaebfb
permissions -rw-r--r--
Was trying to get manufacturer string.
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@23
    15
        public static extern Boolean HidD_GetManufacturerString(/*SafeFileHandle*/ IntPtr HidDeviceObject, StringBuilder Buffer, Int32 BufferLength);
sl@23
    16
sl@17
    17
    }
sl@17
    18
sl@17
    19
sl@17
    20
    static partial class Macro
sl@17
    21
    {
sl@17
    22
sl@17
    23
sl@17
    24
    }
sl@17
    25
sl@17
    26
sl@17
    27
    static partial class Const
sl@17
    28
    {
sl@17
    29
sl@17
    30
sl@17
    31
    }
sl@17
    32
sl@17
    33
sl@17
    34
    public enum HIDP_REPORT_TYPE : ushort
sl@17
    35
    {
sl@17
    36
        HidP_Input = 0,
sl@17
    37
        HidP_Output,
sl@17
    38
        HidP_Feature
sl@17
    39
    }
sl@17
    40
sl@17
    41
sl@17
    42
    public enum HidStatus : uint
sl@17
    43
    {
sl@17
    44
        HIDP_STATUS_SUCCESS = 0x110000,
sl@17
    45
        HIDP_STATUS_NULL = 0x80110001,
sl@17
    46
        HIDP_STATUS_INVALID_PREPARSED_DATA = 0xc0110001,
sl@17
    47
        HIDP_STATUS_INVALID_REPORT_TYPE = 0xc0110002,
sl@17
    48
        HIDP_STATUS_INVALID_REPORT_LENGTH = 0xc0110003,
sl@17
    49
        HIDP_STATUS_USAGE_NOT_FOUND = 0xc0110004,
sl@17
    50
        HIDP_STATUS_VALUE_OUT_OF_RANGE = 0xc0110005,
sl@17
    51
        HIDP_STATUS_BAD_LOG_PHY_VALUES = 0xc0110006,
sl@17
    52
        HIDP_STATUS_BUFFER_TOO_SMALL = 0xc0110007,
sl@17
    53
        HIDP_STATUS_INTERNAL_ERROR = 0xc0110008,
sl@17
    54
        HIDP_STATUS_I8042_TRANS_UNKNOWN = 0xc0110009,
sl@17
    55
        HIDP_STATUS_INCOMPATIBLE_REPORT_ID = 0xc011000a,
sl@17
    56
        HIDP_STATUS_NOT_VALUE_ARRAY = 0xc011000b,
sl@17
    57
        HIDP_STATUS_IS_VALUE_ARRAY = 0xc011000c,
sl@17
    58
        HIDP_STATUS_DATA_INDEX_NOT_FOUND = 0xc011000d,
sl@17
    59
        HIDP_STATUS_DATA_INDEX_OUT_OF_RANGE = 0xc011000e,
sl@17
    60
        HIDP_STATUS_BUTTON_NOT_PRESSED = 0xc011000f,
sl@17
    61
        HIDP_STATUS_REPORT_DOES_NOT_EXIST = 0xc0110010,
sl@17
    62
        HIDP_STATUS_NOT_IMPLEMENTED = 0xc0110020,
sl@17
    63
        HIDP_STATUS_I8242_TRANS_UNKNOWN = 0xc0110009
sl@17
    64
    }
sl@17
    65
sl@17
    66
sl@17
    67
    [StructLayout(LayoutKind.Sequential)]
sl@17
    68
    public struct USAGE_AND_PAGE
sl@17
    69
    {
sl@17
    70
        public ushort Usage;
sl@17
    71
        public ushort UsagePage;
sl@17
    72
    };
sl@17
    73
sl@17
    74
sl@17
    75
}