⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 osinterface.bas

📁 利用psoc进行usb及capsense的程序编写
💻 BAS
字号:
Attribute VB_Name = "APIinterface"
Option Explicit
' This module is common to all of the Example programs
' It declares the data types and system calls required to access the Windows operating system
'
' Copyright 2005, John Hyde, USB Design By Example
' You may use this program for development but you may not sell or publish it
' without written permission from the author

' C and Visual Basic need to cooperate on variable sizes:
' 8bits = byte
'16bits = integer
'32bits = long
'
' Visual Basic passes ADDRESSES of variables into subroutines/functions.  This is typically what C needs.
' If a VALUE is needed then the subroutine/function parameter must be prefixed with 'ByVal'
'
' To learn more read Dan Appleman's book "Visual Basic Programmers Guide to the Win32 API"
'
Public Const GENERIC_READ = &H80000000
Public Const GENERIC_WRITE = &H40000000
Public Const FILE_SHARE_NONE = 0
Public Const FILE_SHARE_READWRITE = 3
Public Const OPEN_EXISTING = 3
Public Const FILE_FLAG_OVERLAPPED = &H40000000
Public Const WAIT_TIMEOUT = &H102
Public Const INVALID_DEVICE_HANDLE = -1
Public Const DIGCF_PRESENT = &H2
Public Const DIGCF_DEVICEINTERFACE = &H10

Public Type SECURITY_ATTRIBUTES
    nLength As Long
    lpSecurityDescriptor As Long
    bInheritHandle As Long
End Type

Public Type OVERLAPPED
    lpInternal As Long
    lpInternalHigh As Long
    Offset As Long
    OffsetHigh As Long
    hEvent As Long
End Type

Public Type GUID
    DataL As Long
    DataI(1) As Integer
    DataB(7) As Byte
End Type

Public Type Device_Interface_Data
    cbSize As Long
    InterfaceClassGuid As GUID
    Flags As Long
    ReservedPtr As Long
End Type
    
Public Type Device_Interface_Detail
    cbSize As Long
    DataPath(256) As Byte
End Type

Public Type ConfigurationDataType
    cookie As Long
    cbSize As Long
    RingBuffersize As Long
End Type

Public Type HIDD_ATTRIBUTES
    cbSize As Long
    VendorID As Integer
    ProductID As Integer
    VersionNumber As Integer
    Reserved As Integer
End Type

Public Type Hid_Capabilities
    Usage As Integer
    UsagePage As Integer
    InputReportByteLength As Integer
    OutputReportByteLength As Integer
    FeatureReportByteLength As Integer
    Reserved(16) As Integer
    NumberLinkCollectionNodes As Integer
    NumberInputButtonCaps As Integer
    NumberInputValueCaps As Integer
    NumberInputDataIndices As Integer
    NumberOutputButtonCaps As Integer
    NumberOutputValueCaps As Integer
    NumberOutputDataIndices As Integer
    NumberFeatureButtonCaps As Integer
    NumberFeatureValueCaps As Integer
    NumberFeatureDataIndices As Integer
End Type

'   Declare the API calls that I am using
Declare Function SetupDiGetClassDevs Lib "setupapi.dll" Alias "SetupDiGetClassDevsA" _
    (HidGuid As GUID, _
     ByVal EnumPtr As Long, _
     ByVal hwndParent As Long, _
     ByVal Flags As Long) As Long

Declare Function SetupDiDestroyDeviceInfoList Lib "setupapi.dll" _
    (ByVal DeviceInfoSet As Long) As Boolean

Declare Function SetupDiEnumDeviceInterfaces Lib "setupapi.dll" _
    (ByVal Handle As Long, _
     ByVal InfoPtr As Long, _
     HidGuid As GUID, _
     ByVal MemberIndex As Long, _
     DeviceInterfaceData As Device_Interface_Data) As Boolean

Declare Function SetupDiGetDeviceInterfaceDetail Lib "setupapi.dll" Alias "SetupDiGetDeviceInterfaceDetailA" _
    (ByVal Handle As Long, _
    DeviceInterfaceData As Device_Interface_Data, _
    FunctionClassDeviceData As Device_Interface_Detail, _
    ByVal DetailLength As Long, _
    lpReturnedLength As Long, _
    ByVal DevInfoDataPtr As Long) As Boolean
 
Declare Function GetLastError Lib "kernel32" () As Long

Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" _
    (ByVal lpFileName As String, _
     ByVal dwDesiredAccess As Long, _
     ByVal dwShareMode As Long, _
     lpSecurityAttributes As SECURITY_ATTRIBUTES, _
     ByVal dwCreationDisposition As Long, _
     ByVal dwFlagsAndAttributes As Long, _
     ByVal hTemplateFile As Long) As Long

Declare Sub CloseHandle Lib "kernel32" (ByVal HandleToClose As Long)

Declare Function ReadFile Lib "kernel32" _
    (ByVal Handle As Long, _
     lpByte As Byte, _
     ByVal ByteCount As Long, _
     lpBytesReturned As Long, _
     OverlappedPtr As OVERLAPPED) As Long

Declare Function WriteFile Lib "kernel32" _
    (ByVal Handle As Long, _
     lpByte As Byte, _
     ByVal ByteCount As Long, _
     lpBytesReturned As Long, _
     ByVal OverlappedPtr As Long) As Long

Public Declare Function CancelIo Lib "kernel32" _
    (ByVal hFile As Long) As Long

Public Declare Function CreateEvent Lib "kernel32" Alias "CreateEventA" _
    (ByVal SecurityAttributes As Long, _
    ByVal bManualReset As Long, _
    ByVal bInitialState As Long, _
    ByVal lpName As String) As Long

Public Declare Function ResetEvent Lib "kernel32" _
    (ByVal hEvent As Long) As Long

Public Declare Function WaitForSingleObject Lib "kernel32" _
    (ByVal hHandle As Long, _
    ByVal dwMilliseconds As Long) As Long

Declare Function HidP_GetCaps Lib "hid.dll" _
    (ByVal lpBufferPtr As Long, _
     lpBufferPtr As Hid_Capabilities) As Long
Declare Function HidD_GetPreparsedData Lib "hid.dll" _
    (ByVal Handle As Long, _
     lpBufferPtr As Long) As Long
Declare Function HidD_GetAttributes Lib "hid.dll" _
    (ByVal Handle As Long, _
     Attributes As HIDD_ATTRIBUTES) As Long
Declare Function HidD_GetManufacturerString Lib "hid.dll" _
    (ByVal Handle As Long, _
     lpBufferPtr As Long, _
     ByVal Length As Long) As Long
Declare Function HidD_GetProductString Lib "hid.dll" _
    (ByVal Handle As Long, _
     lpBufferPtr As Long, _
     ByVal Length As Long) As Long
Declare Function HidD_GetSerialNumberString Lib "hid.dll" _
    (ByVal Handle As Long, _
     lpBufferPtr As Long, _
     ByVal Length As Long) As Long
Declare Function HidD_GetIndexedString Lib "hid.dll" _
    (ByVal Handle As Long, _
     ByVal index As Long, _
     lpBufferPtr As Long, _
     ByVal Length As Long) As Long
Declare Function HidD_GetConfiguration Lib "hid.dll" _
    (ByVal Handle As Long, _
     lpBufferPtr As Long, _
     ByVal Length As Long) As Long
Declare Function HidD_SetConfiguration Lib "hid.dll" _
    (ByVal Handle As Long, _
     lpBufferPtr As Long, _
     ByVal Length As Long) As Long
Declare Function HidD_GetPhysicalDescriptor Lib "hid.dll" _
    (ByVal Handle As Long, _
     lpBufferPtr As Long, _
     ByVal Length As Long) As Long
Declare Sub HidD_GetHidGuid Lib "hid.dll" (HidGuid As GUID)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -