📄 winusbdevicedeclarations.vb
字号:
Option Strict On
Option Explicit On
Imports System.Runtime.InteropServices
'''<summary>
''' These declarations are translated from the C declarations in various files
''' in the Windows DDK. The files are:
'''
''' winddk\6001\inc\api\usb.h
''' winddk\6001\inc\api\usb100.h
''' winddk\6001\inc\api\winusbio.h
'''
''' (your home directory and release number may vary)
'''</summary>
Module WinUsbDeviceDeclarations
Public Const DEVICE_SPEED As UInt32 = 1
Public Const USB_ENDPOINT_DIRECTION_MASK As Byte = &H80
Public Enum POLICY_TYPE
SHORT_PACKET_TERMINATE = 1
AUTO_CLEAR_STALL
PIPE_TRANSFER_TIMEOUT
IGNORE_SHORT_PACKETS
ALLOW_PARTIAL_READS
AUTO_FLUSH
RAW_IO
End Enum
Public Enum USBD_PIPE_TYPE
UsbdPipeTypeControl
UsbdPipeTypeIsochronous
UsbdPipeTypeBulk
UsbdPipeTypeInterrupt
End Enum
Public Enum USB_DEVICE_SPEED
UsbLowSpeed
UsbFullSpeed
UsbHighSpeed
End Enum
<StructLayout(LayoutKind.Sequential)> _
Public Structure USB_CONFIGURATION_DESCRIPTOR
Dim bLength As Byte
Dim bDescriptorType As Byte
Dim wTotalLength As UShort
Dim bNumInterfaces As Byte
Dim bConfigurationValue As Byte
Dim iConfiguration As Byte
Dim bmAttributes As Byte
Dim MaxPower As Byte
End Structure
<StructLayout(LayoutKind.Sequential)> _
Public Structure USB_INTERFACE_DESCRIPTOR
Dim bLength As Byte
Dim bDescriptorType As Byte
Dim bInterfaceNumber As Byte
Dim bAlternateSetting As Byte
Dim bNumEndpoints As Byte
Dim bInterfaceClass As Byte
Dim bInterfaceSubClass As Byte
Dim bInterfaceProtocol As Byte
Dim iInterface As Byte
End Structure
<StructLayout(LayoutKind.Sequential)> _
Public Structure WINUSB_PIPE_INFORMATION
Dim PipeType As USBD_PIPE_TYPE
Dim PipeId As Byte
Dim MaximumPacketSize As UShort
Dim Interval As Byte
End Structure
<StructLayout(LayoutKind.Sequential, Pack:=1)> _
Public Structure WINUSB_SETUP_PACKET
Dim RequestType As Byte
Dim Request As Byte
Dim Value As UShort
Dim Index As UShort
Dim Length As UShort
End Structure
<DllImport("winusb.dll")> Function WinUsb_ControlTransfer _
(ByVal InterfaceHandle As Integer, _
ByVal SetupPacket As WINUSB_SETUP_PACKET, _
ByRef Buffer As Byte, _
ByVal BufferLength As UInt32, _
ByRef LengthTransferred As UInt32, _
ByVal Overlapped As IntPtr) _
As Boolean
End Function
<DllImport("winusb.dll")> Function WinUsb_Free _
(ByVal InterfaceHandle As Integer) _
As Boolean
End Function
<DllImport("winusb.dll")> Function WinUsb_Initialize _
(ByVal DeviceHandle As Integer, _
ByRef InterfaceHandle As Integer) _
As Boolean
End Function
' winusb.h
' In the C declaration, Buffer is a pvoid, with no equivalent in Visual Basic.
' Use this declaration to retrieve DEVICE_SPEED (the only currently defined InformationType).
<DllImport("winusb.dll")> Function WinUsb_QueryDeviceInformation _
(ByVal InterfaceHandle As Integer, _
ByVal InformationType As UInt32, _
ByRef BufferLength As UInt32, _
ByRef Buffer As Byte) _
As Boolean
End Function
<DllImport("winusb.dll")> Function WinUsb_QueryInterfaceSettings _
(ByVal InterfaceHandle As Integer, _
ByVal AlternateInterfaceNumber As Byte, _
ByRef UsbAltInterfaceDescriptor As USB_INTERFACE_DESCRIPTOR) _
As Boolean
End Function
<DllImport("winusb.dll")> Function WinUsb_QueryPipe _
(ByVal InterfaceHandle As Integer, _
ByVal AlternateInterfaceNumber As Byte, _
ByVal PipeIndex As Byte, _
ByRef PipeInformation As WINUSB_PIPE_INFORMATION) _
As Boolean
End Function
<DllImport("winusb.dll")> Function WinUsb_ReadPipe _
(ByVal InterfaceHandle As Integer, _
ByVal PipeID As Byte, _
ByRef Buffer As Byte, _
ByVal BufferLength As UInt32, _
ByRef LengthTransferred As UInt32, _
ByVal Overlapped As IntPtr) _
As Boolean
End Function
' Two declarations for WinUsb_SetPipePolicy.
' Use this one when the returned Value is a byte (all except PIPE_TRANSFER_TIMEOUT):
<DllImport("winusb.dll")> Function WinUsb_SetPipePolicy _
(ByVal InterfaceHandle As Integer, _
ByVal PipeID As Byte, _
ByVal PolicyType As UInt32, _
ByVal ValueLength As UInt32, _
ByRef Value As Byte) _
As Boolean
End Function
' Use this alias when the returned Value is a UInt32 (PIPE_TRANSFER_TIMEOUT only):
<DllImport("winusb.dll", EntryPoint:="WinUsb_SetPipePolicy")> Function WinUsb_SetPipePolicy1 _
(ByVal InterfaceHandle As Integer, _
ByVal PipeID As Byte, _
ByVal PolicyType As UInt32, _
ByVal ValueLength As UInt32, _
ByRef Value As UInt32) _
As Boolean
End Function
<DllImport("winusb.dll")> Function WinUsb_WritePipe _
(ByVal InterfaceHandle As Integer, _
ByVal PipeID As Byte, _
ByRef Buffer As Byte, _
ByVal BufferLength As UInt32, _
ByRef LengthTransferred As UInt32, _
ByVal Overlapped As IntPtr) _
As Boolean
End Function
End Module
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -