資源簡介
網上下載的C#讀寫HID的代碼修改的,https://blog.csdn.net/u010875635/article/details/73321066,沒積分請到https://github.com/beatfan/HID_Communication下載原始代碼。

代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.Linq;
using?System.Text;
using?System.Runtime.InteropServices;
using?System.Collections;
namespace?Hid_test
{
????public?class?ClassHid
????{
????????Guid?guidHID?=?Guid.Empty;
????????IntPtr?hDevInfo;
????????//以下是調用windows的API的函數
????????//獲得GUID
????????[DllImport(“hid.dll“)]
????????public?static?extern?void?HidD_GetHidGuid(ref?Guid?HidGuid);
????????public?enum?DIGCF
????????{
????????????DIGCF_DEFAULT?=?0x1
????????????DIGCF_PRESENT?=?0x2
????????????DIGCF_ALLCLASSES?=?0x4
????????????DIGCF_PROFILE?=?0x8
????????????DIGCF_DEVICEINTERFACE?=?0x10
????????}
????????//過濾設備,獲取需要的設備
????????[DllImport(“setupapi.dll“?SetLastError?=?true)]
????????public?static?extern?IntPtr?SetupDiGetClassDevs(ref?Guid?ClassGuid?uint?Enumerator?IntPtr?HwndParent?DIGCF?Flags);
????????//獲取設備,true獲取到
????????public?struct?SP_DEVICE_INTERFACE_DATA
????????{
????????????public?int?cbSize;
????????????public?Guid?interfaceClassGuid;
????????????public?int?flags;
????????????public?int?reserved;
????????}
????????[DllImport(“setupapi.dll“?CharSet?=?CharSet.Auto?SetLastError?=?true)]
????????public?static?extern?Boolean?SetupDiEnumDeviceInterfaces(IntPtr?hDevInfo?IntPtr?devInfo?ref?Guid?interfaceClassGuid?UInt32?memberIndex?ref?SP_DEVICE_INTERFACE_DATA?deviceInterfaceData);
????????
????????//?獲取接口的詳細信息?必須調用兩次?第1次返回長度?第2次獲取數據?
????????[StructLayout(LayoutKind.Sequential)]
????????public?class?SP_DEVINFO_DATA
????????{
????????????public?int?cbSize?=?Marshal.SizeOf(typeof(SP_DEVINFO_DATA));
????????????public?Guid?classGuid?=?Guid.Empty;?//?temp
????????????public?int?devInst?=?0;?//?dumy
????????????public?int?reserved?=?0;
????????}
????????[StructLayout(LayoutKind.Sequential?Pack?=?2)]
????????internal?struct?SP_DEVICE_INTERFACE_DETAIL_DATA
????????{
????????????internal?int?cbSize;
????????????internal?short?devicePath;
????????}
????????[DllImport(“setupapi.dll“?SetLastError?=?true?CharSet?=?CharSet.Auto)]
????????private?static?extern?bool?SetupDiGetDeviceInterfaceDetail(IntPtr?deviceInfoSet?ref?SP_DEVICE_INTERFACE_DATA?deviceInterfaceData?IntPtr?deviceInterfaceDetailData
????????????int?deviceInterfaceDetailDataSize?ref?int?requiredSize?SP_DEVINFO_DATA?deviceInfoData);
????????//獲取設備文件
????????[DllImport(“kernel32.dll“?SetLastError?=?true)]
????????private?static?extern?int?CreateFile(
????????????string?lpFileName????????????????????????????//?file?name
????????????uint?dwDesiredAccess????????????????????????//?access?mode
????????????uint?dwShareMode????????????????????????????//?share?mode
????????????uint?lpSecurityAttributes????????????????????//?SD
????????????uint?dwCreationDisposition????????????????????//?how?to?create
????????????uint?dwFlagsAndAttributes????????????????????//?file?attributes
????????????uint?hTemplateFile????????????????????????????//?handle?to
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????307??2018-05-03?10:27??HID_Communication\.git\config
?????文件?????????73??2018-05-03?10:27??HID_Communication\.git\desc
?????文件?????????23??2018-05-03?10:27??HID_Communication\.git\HEAD
?????文件????????478??2018-05-03?10:27??HID_Communication\.git\hooks\applypatch-msg.sample
?????文件????????896??2018-05-03?10:27??HID_Communication\.git\hooks\commit-msg.sample
?????文件????????189??2018-05-03?10:27??HID_Communication\.git\hooks\post-update.sample
?????文件????????424??2018-05-03?10:27??HID_Communication\.git\hooks\pre-applypatch.sample
?????文件???????1642??2018-05-03?10:27??HID_Communication\.git\hooks\pre-commit.sample
?????文件???????1348??2018-05-03?10:27??HID_Communication\.git\hooks\pre-push.sample
?????文件???????4951??2018-05-03?10:27??HID_Communication\.git\hooks\pre-reba
?????文件????????544??2018-05-03?10:27??HID_Communication\.git\hooks\pre-receive.sample
?????文件???????1239??2018-05-03?10:27??HID_Communication\.git\hooks\prepare-commit-msg.sample
?????文件???????3610??2018-05-03?10:27??HID_Communication\.git\hooks\update.sample
?????文件???????2205??2018-05-03?10:27??HID_Communication\.git\index
?????文件????????240??2018-05-03?10:27??HID_Communication\.git\info\exclude
?????文件????????191??2018-05-03?10:27??HID_Communication\.git\logs\HEAD
?????文件????????191??2018-05-03?10:27??HID_Communication\.git\logs\refs\heads\master
?????文件????????191??2018-05-03?10:27??HID_Communication\.git\logs\refs\remotes\origin\HEAD
?????文件?????????40??2018-05-03?10:27??HID_Communication\.git\ob
?????文件???????1184??2018-05-03?10:27??HID_Communication\.git\ob
?????文件???????1730??2018-05-03?10:27??HID_Communication\.git\ob
?????文件????????136??2018-05-03?10:27??HID_Communication\.git\ob
?????文件?????????35??2018-05-03?10:27??HID_Communication\.git\ob
?????文件????????367??2018-05-03?10:27??HID_Communication\.git\ob
?????文件????????186??2018-05-03?10:27??HID_Communication\.git\ob
?????文件????????910??2018-05-03?10:27??HID_Communication\.git\ob
?????文件???????3974??2018-05-03?10:27??HID_Communication\.git\ob
?????文件????????163??2018-05-03?10:27??HID_Communication\.git\ob
?????文件????????384??2018-05-03?10:27??HID_Communication\.git\ob
?????文件????????783??2018-05-03?10:27??HID_Communication\.git\ob
............此處省略117個文件信息
評論
共有 條評論