#Region "Copyright (c) Travis Robinson" ' Copyright (c) 2011-2021 Travis Robinson ' All rights reserved. ' ' C# libusbK Bindings ' Auto-generated on: 07.08.2021 ' ' Redistribution and use in source and binary forms, with or without ' modification, are permitted provided that the following conditions are met: ' ' * Redistributions of source code must retain the above copyright ' notice, this list of conditions and the following disclaimer. ' ' THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS ' IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED ' TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A ' PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL TRAVIS LEE ROBINSON ' BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR ' CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF ' SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS ' INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN ' CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ' ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF ' THE POSSIBILITY OF SUCH DAMAGE. #End Region Imports System Imports System.Diagnostics Imports System.Runtime.InteropServices ' ReSharper disable InconsistentNaming ' ReSharper disable CheckNamespace ' ReSharper disable UnassignedReadonlyField Namespace libusbK Public Module AllKOptions ''' ''' Alternate libusbK library to use. This must be assigned before any libusbK functions are called and it must be the ''' full path and file name to a libusbK.dll. ''' Public LIBUSBK_FULLPATH_TO_ALTERNATE_DLL As String End Module Public Module AllKConstants ''' ''' Allocated length for all strings in a \ref KLST_DEVINFO structure. ''' Public Const KLST_STRING_MAX_LEN As Integer = 256 ''' ''' libusbK library ''' Public Const LIBUSBK_DLL As String = "libusbK.dll" ''' ''' Config power mask for the \c bmAttributes field of a \ref USB_CONFIGURATION_DESCRIPTOR ''' Public Const USB_CONFIG_POWERED_MASK As Byte = &HC0 ''' ''' Endpoint direction mask for the \c bEndpointAddress field of a \ref USB_ENDPOINT_DESCRIPTOR ''' Public Const USB_ENDPOINT_DIRECTION_MASK As Byte = &H80 ''' ''' Endpoint address mask for the \c bEndpointAddress field of a \ref USB_ENDPOINT_DESCRIPTOR ''' Public Const USB_ENDPOINT_ADDRESS_MASK As Byte = &H0F End Module Public Enum PipePolicyType SHORT_PACKET_TERMINATE = &H01 AUTO_CLEAR_STALL = &H02 PIPE_TRANSFER_TIMEOUT = &H03 IGNORE_SHORT_PACKETS = &H04 ALLOW_PARTIAL_READS = &H05 AUTO_FLUSH = &H06 RAW_IO = &H07 MAXIMUM_TRANSFER_SIZE = &H08 RESET_PIPE_ON_RESUME = &H09 ISO_START_LATENCY = &H20 ISO_ALWAYS_START_ASAP = &H21 ISO_NUM_FIXED_PACKETS = &H22 SIMUL_PARALLEL_REQUESTS = &H30 End Enum Public Enum PowerPolicyType AUTO_SUSPEND = &H81 SUSPEND_DELAY = &H83 End Enum Public Enum DeviceInformationType DEVICE_SPEED = &H01 End Enum Public Enum EndpointType ''' ''' Indicates a control endpoint ''' CONTROL = &H00 ''' ''' Indicates an isochronous endpoint ''' ISOCHRONOUS = &H01 ''' ''' Indicates a bulk endpoint ''' BULK = &H02 ''' ''' Indicates an interrupt endpoint ''' INTERRUPT = &H03 ''' ''' Endpoint type mask for the \c bmAttributes field of a \ref USB_ENDPOINT_DESCRIPTOR ''' MASK = &H03 End Enum Public Module ErrorCodes ''' ''' The operation completed successfully. ''' Public Const Success As Integer = 0 ''' ''' Access is denied. ''' Public Const AccessDenied As Integer = 5 ''' ''' The handle is invalid. ''' Public Const InvalidHandle As Integer = 6 ''' ''' Not enough storage is available to process this command. ''' Public Const NotEnoughMemory As Integer = 8 ''' ''' The request is not supported. ''' Public Const NotSupported As Integer = 50 ''' ''' The parameter is incorrect. ''' Public Const InvalidParameter As Integer = 87 ''' ''' The semaphore timeout period has expired. ''' Public Const SemTimeout As Integer = 121 ''' ''' The requested resource is in use. ''' Public Const Busy As Integer = 170 ''' ''' Too many dynamic-link modules are attached to this program or dynamic-link module. ''' Public Const TooManyModules As Integer = 214 ''' ''' More data is available. ''' Public Const MoreData As Integer = 234 ''' ''' No more data is available. ''' Public Const NoMoreItems As Integer = 259 ''' ''' An attempt was made to operate on a thread within a specific process, but the thread specified is not in the ''' process specified. ''' Public Const ThreadNotInProcess As Integer = 566 ''' ''' A thread termination occurred while the thread was suspended. The thread was resumed, and termination proceeded. ''' Public Const ThreadWasSuspended As Integer = 699 ''' ''' The I/O operation has been aborted because of either a thread exit or an application request. ''' Public Const OperationAborted As Integer = 995 ''' ''' Overlapped I/O event is not in a signaled state. ''' Public Const IoIncomplete As Integer = 996 ''' ''' Overlapped I/O operation is in progress. ''' Public Const IoPending As Integer = 997 ''' ''' Element not found. ''' Public Const NotFound As Integer = 1168 ''' ''' The operation was canceled by the user. ''' Public Const Cancelled As Integer = 1223 ''' ''' The library, drive, or media pool is empty. ''' Public Const Empty As Integer = 4306 ''' ''' The cluster resource is not available. ''' Public Const ResourceNotAvailable As Integer = 5006 ''' ''' The cluster resource could not be found. ''' Public Const ResourceNotFound As Integer = 5007 End Module Public Interface IKLIB_HANDLE ReadOnly Property HandleType As KLIB_HANDLE_TYPE ReadOnly Property Pointer As IntPtr Function GetContext() As IntPtr Function SetContext(ByVal UserContext As IntPtr) As Boolean Function SetCleanupCallback(ByVal CleanupCallback As KLIB_HANDLE_CLEANUP_CB) As Boolean End Interface ''' ''' A structure representing additional information about super speed (or higher) endpoints. ''' Public Structure USB_SUPERSPEED_ENDPOINT_COMPANION_DESCRIPTOR ''' Size of this descriptor (in bytes) Public bLength As Byte ''' Descriptor type Public bDescriptorType As Byte ''' Specifies the maximum number of packets that the endpoint can send or receive as a part of a burst. Public bMaxBurst As Byte Public AsUchar As Byte ''' Number of bytes per interval Public wBytesPerInterval As UShort ''' Specifies the maximum number of streams supported by the bulk endpoint. Public ReadOnly Property BulkMaxStreams As Byte Get Return AsUchar And &H1F End Get End Property ''' ''' Specifies a zero-based number that determines the maximum number of packets (bMaxBurst * (Mult + 1)) that can ''' be sent to the endpoint within a service interval. ''' Public ReadOnly Property IsoMult As Byte Get Return AsUchar And &H3 End Get End Property Public ReadOnly Property SspCompanion As Byte Get Return AsUchar >> 7 End Get End Property End Structure #Region "Opaque library handles" Public Structure KLST_HANDLE Implements IKLIB_HANDLE Private ReadOnly mHandlePtr As IntPtr Public Sub New(ByVal Handle As IntPtr) mHandlePtr = Handle End Sub Public ReadOnly Property Pointer As IntPtr Implements IKLIB_HANDLE.Pointer Get Return mHandlePtr End Get End Property Public ReadOnly Property HandleType As KLIB_HANDLE_TYPE Implements IKLIB_HANDLE.HandleType Get Return KLIB_HANDLE_TYPE.LSTK End Get End Property Public Function GetContext() As IntPtr Implements IKLIB_HANDLE.GetContext Return LibK_GetContext(mHandlePtr, HandleType) End Function Public Function SetContext(ByVal UserContext As IntPtr) As Boolean Implements IKLIB_HANDLE.SetContext Return LibK_SetContext(mHandlePtr, HandleType, UserContext) End Function Public Function SetCleanupCallback(ByVal CleanupCallback As KLIB_HANDLE_CLEANUP_CB) As Boolean Implements IKLIB_HANDLE.SetCleanupCallback Return LibK_SetCleanupCallback(mHandlePtr, HandleType, CleanupCallback) End Function End Structure Public Structure KHOT_HANDLE Implements IKLIB_HANDLE Private ReadOnly mHandlePtr As IntPtr Public Sub New(ByVal Handle As IntPtr) mHandlePtr = Handle End Sub Public ReadOnly Property Pointer As IntPtr Implements IKLIB_HANDLE.Pointer Get Return mHandlePtr End Get End Property Public ReadOnly Property HandleType As KLIB_HANDLE_TYPE Implements IKLIB_HANDLE.HandleType Get Return KLIB_HANDLE_TYPE.HOTK End Get End Property Public Function GetContext() As IntPtr Implements IKLIB_HANDLE.GetContext Return LibK_GetContext(mHandlePtr, HandleType) End Function Public Function SetContext(ByVal UserContext As IntPtr) As Boolean Implements IKLIB_HANDLE.SetContext Return LibK_SetContext(mHandlePtr, HandleType, UserContext) End Function Public Function SetCleanupCallback(ByVal CleanupCallback As KLIB_HANDLE_CLEANUP_CB) As Boolean Implements IKLIB_HANDLE.SetCleanupCallback Return LibK_SetCleanupCallback(mHandlePtr, HandleType, CleanupCallback) End Function End Structure Public Structure KUSB_HANDLE Implements IKLIB_HANDLE Private ReadOnly mHandlePtr As IntPtr Public Sub New(ByVal Handle As IntPtr) mHandlePtr = Handle End Sub Public ReadOnly Property Pointer As IntPtr Implements IKLIB_HANDLE.Pointer Get Return mHandlePtr End Get End Property Public ReadOnly Property HandleType As KLIB_HANDLE_TYPE Implements IKLIB_HANDLE.HandleType Get Return KLIB_HANDLE_TYPE.USBK End Get End Property Public Function GetContext() As IntPtr Implements IKLIB_HANDLE.GetContext Return LibK_GetContext(mHandlePtr, HandleType) End Function Public Function SetContext(ByVal UserContext As IntPtr) As Boolean Implements IKLIB_HANDLE.SetContext Return LibK_SetContext(mHandlePtr, HandleType, UserContext) End Function Public Function SetCleanupCallback(ByVal CleanupCallback As KLIB_HANDLE_CLEANUP_CB) As Boolean Implements IKLIB_HANDLE.SetCleanupCallback Return LibK_SetCleanupCallback(mHandlePtr, HandleType, CleanupCallback) End Function #Region "USB Shared Device Context" Public Function GetSharedContext() As IntPtr Return LibK_GetContext(mHandlePtr, KLIB_HANDLE_TYPE.USBSHAREDK) End Function Public Function SetSharedContext(ByVal UserContext As IntPtr) As Boolean Return LibK_SetContext(mHandlePtr, KLIB_HANDLE_TYPE.USBSHAREDK, UserContext) End Function Public Function SetSharedCleanupCallback(ByVal CleanupCallback As KLIB_HANDLE_CLEANUP_CB) As Boolean Return LibK_SetCleanupCallback(mHandlePtr, KLIB_HANDLE_TYPE.USBSHAREDK, CleanupCallback) End Function #End Region End Structure Public Structure KOVL_POOL_HANDLE Implements IKLIB_HANDLE Private ReadOnly mHandlePtr As IntPtr Public Sub New(ByVal Handle As IntPtr) mHandlePtr = Handle End Sub Public ReadOnly Property Pointer As IntPtr Implements IKLIB_HANDLE.Pointer Get Return mHandlePtr End Get End Property Public ReadOnly Property HandleType As KLIB_HANDLE_TYPE Implements IKLIB_HANDLE.HandleType Get Return KLIB_HANDLE_TYPE.OVLPOOLK End Get End Property Public Function GetContext() As IntPtr Implements IKLIB_HANDLE.GetContext Return LibK_GetContext(mHandlePtr, HandleType) End Function Public Function SetContext(ByVal UserContext As IntPtr) As Boolean Implements IKLIB_HANDLE.SetContext Return LibK_SetContext(mHandlePtr, HandleType, UserContext) End Function Public Function SetCleanupCallback(ByVal CleanupCallback As KLIB_HANDLE_CLEANUP_CB) As Boolean Implements IKLIB_HANDLE.SetCleanupCallback Return LibK_SetCleanupCallback(mHandlePtr, HandleType, CleanupCallback) End Function End Structure Public Structure KOVL_HANDLE Implements IKLIB_HANDLE Private ReadOnly mHandlePtr As IntPtr Public Sub New(ByVal Handle As IntPtr) mHandlePtr = Handle End Sub Public ReadOnly Property Pointer As IntPtr Implements IKLIB_HANDLE.Pointer Get Return mHandlePtr End Get End Property Public ReadOnly Property HandleType As KLIB_HANDLE_TYPE Implements IKLIB_HANDLE.HandleType Get Return KLIB_HANDLE_TYPE.OVLK End Get End Property Public Function GetContext() As IntPtr Implements IKLIB_HANDLE.GetContext Return LibK_GetContext(mHandlePtr, HandleType) End Function Public Function SetContext(ByVal UserContext As IntPtr) As Boolean Implements IKLIB_HANDLE.SetContext Return LibK_SetContext(mHandlePtr, HandleType, UserContext) End Function Public Function SetCleanupCallback(ByVal CleanupCallback As KLIB_HANDLE_CLEANUP_CB) As Boolean Implements IKLIB_HANDLE.SetCleanupCallback Return LibK_SetCleanupCallback(mHandlePtr, HandleType, CleanupCallback) End Function End Structure Public Structure KSTM_HANDLE Implements IKLIB_HANDLE Private ReadOnly mHandlePtr As IntPtr Public Sub New(ByVal Handle As IntPtr) mHandlePtr = Handle End Sub Public ReadOnly Property Pointer As IntPtr Implements IKLIB_HANDLE.Pointer Get Return mHandlePtr End Get End Property Public ReadOnly Property HandleType As KLIB_HANDLE_TYPE Implements IKLIB_HANDLE.HandleType Get Return KLIB_HANDLE_TYPE.STMK End Get End Property Public Function GetContext() As IntPtr Implements IKLIB_HANDLE.GetContext Return LibK_GetContext(mHandlePtr, HandleType) End Function Public Function SetContext(ByVal UserContext As IntPtr) As Boolean Implements IKLIB_HANDLE.SetContext Return LibK_SetContext(mHandlePtr, HandleType, UserContext) End Function Public Function SetCleanupCallback(ByVal CleanupCallback As KLIB_HANDLE_CLEANUP_CB) As Boolean Implements IKLIB_HANDLE.SetCleanupCallback Return LibK_SetCleanupCallback(mHandlePtr, HandleType, CleanupCallback) End Function End Structure Public Structure KISOCH_HANDLE Implements IKLIB_HANDLE Private ReadOnly mHandlePtr As IntPtr Public Sub New(ByVal Handle As IntPtr) mHandlePtr = Handle End Sub Public ReadOnly Property Pointer As IntPtr Implements IKLIB_HANDLE.Pointer Get Return mHandlePtr End Get End Property Public ReadOnly Property HandleType As KLIB_HANDLE_TYPE Implements IKLIB_HANDLE.HandleType Get Return KLIB_HANDLE_TYPE.ISOCHK End Get End Property Public Function GetContext() As IntPtr Implements IKLIB_HANDLE.GetContext Return LibK_GetContext(mHandlePtr, HandleType) End Function Public Function SetContext(ByVal UserContext As IntPtr) As Boolean Implements IKLIB_HANDLE.SetContext Return LibK_SetContext(mHandlePtr, HandleType, UserContext) End Function Public Function SetCleanupCallback(ByVal CleanupCallback As KLIB_HANDLE_CLEANUP_CB) As Boolean Implements IKLIB_HANDLE.SetCleanupCallback Return LibK_SetCleanupCallback(mHandlePtr, HandleType, CleanupCallback) End Function End Structure #End Region #Region "Internal Function Imports" Friend Module AllKFunctions Public Delegate Sub HotK_FreeAllDelegate() Public Delegate Function HotK_FreeDelegate( <[In]> ByVal Handle As KHOT_HANDLE) As Boolean Public Delegate Function HotK_InitDelegate( ByRef Handle As KHOT_HANDLE, <[In]> ByRef InitParams As KHOT_PARAMS) As Boolean Public Delegate Function IsochK_CalcPacketInformationDelegate(ByVal IsHighSpeed As Boolean, <[In]> ByRef PipeInformationEx As WINUSB_PIPE_INFORMATION_EX, ByRef PacketInformation As KISOCH_PACKET_INFORMATION) As Boolean Public Delegate Function IsochK_EnumPacketsDelegate( <[In]> ByVal IsochHandle As KISOCH_HANDLE, ByVal EnumPackets As KISOCH_ENUM_PACKETS_CB, ByVal StartPacketIndex As UInteger, ByVal UserState As IntPtr) As Boolean Public Delegate Function IsochK_FreeDelegate( <[In]> ByVal IsochHandle As KISOCH_HANDLE) As Boolean Public Delegate Function IsochK_GetNumberOfPacketsDelegate( <[In]> ByVal IsochHandle As KISOCH_HANDLE, ByRef NumberOfPackets As UInteger) As Boolean Public Delegate Function IsochK_GetPacketDelegate( <[In]> ByVal IsochHandle As KISOCH_HANDLE, ByVal PacketIndex As UInteger, ByRef Offset As UInteger, ByRef Length As UInteger, ByRef Status As UInteger) As Boolean Public Delegate Function IsochK_InitDelegate( ByRef IsochHandle As KISOCH_HANDLE, <[In]> ByVal InterfaceHandle As KUSB_HANDLE, ByVal PipeId As Byte, ByVal MaxNumberOfPackets As UInteger, ByVal TransferBuffer As IntPtr, ByVal TransferBufferSize As UInteger) As Boolean Public Delegate Function IsochK_SetNumberOfPacketsDelegate( <[In]> ByVal IsochHandle As KISOCH_HANDLE, ByVal NumberOfPackets As UInteger) As Boolean Public Delegate Function IsochK_SetPacketDelegate( <[In]> ByVal IsochHandle As KISOCH_HANDLE, ByVal PacketIndex As UInteger, ByVal Offset As UInteger, ByVal Length As UInteger, ByVal Status As UInteger) As Boolean Public Delegate Function IsochK_SetPacketOffsetsDelegate( <[In]> ByVal IsochHandle As KISOCH_HANDLE, ByVal PacketSize As UInteger) As Boolean Public Delegate Function IsoK_EnumPacketsDelegate( <[In]> ByVal IsoContext As KISO_CONTEXT, ByVal EnumPackets As KISO_ENUM_PACKETS_CB, ByVal StartPacketIndex As Integer, ByVal UserState As IntPtr) As Boolean Public Delegate Function IsoK_FreeDelegate( <[In]> ByVal IsoContext As KISO_CONTEXT) As Boolean Public Delegate Function IsoK_GetPacketDelegate( <[In]> ByVal IsoContext As KISO_CONTEXT, ByVal PacketIndex As Integer, ByRef IsoPacket As KISO_PACKET) As Boolean Public Delegate Function IsoK_InitDelegate( ByRef IsoContext As KISO_CONTEXT, ByVal NumberOfPackets As Integer, ByVal StartFrame As Integer) As Boolean Public Delegate Function IsoK_ReUseDelegate( <[In]> ByVal IsoContext As KISO_CONTEXT) As Boolean Public Delegate Function IsoK_SetPacketDelegate( <[In]> ByVal IsoContext As KISO_CONTEXT, ByVal PacketIndex As Integer, <[In]> ByRef IsoPacket As KISO_PACKET) As Boolean Public Delegate Function IsoK_SetPacketsDelegate( <[In]> ByVal IsoContext As KISO_CONTEXT, ByVal PacketSize As Integer) As Boolean Public Delegate Sub LibK_Context_FreeDelegate() Public Delegate Function LibK_Context_InitDelegate(ByVal Heap As IntPtr, ByVal Reserved As IntPtr) As Boolean Public Delegate Function LibK_CopyDriverAPIDelegate( ByRef DriverAPI As KUSB_DRIVER_API, <[In]> ByVal UsbHandle As KUSB_HANDLE) As Boolean Public Delegate Function LibK_GetContextDelegate( <[In]> ByVal Handle As IntPtr, ByVal HandleType As KLIB_HANDLE_TYPE) As IntPtr Public Delegate Function LibK_GetDefaultContextDelegate(ByVal HandleType As KLIB_HANDLE_TYPE) As IntPtr Public Delegate Function LibK_GetProcAddressDelegate(ByVal ProcAddress As IntPtr, ByVal DriverID As Integer, ByVal FunctionID As Integer) As Boolean Public Delegate Sub LibK_GetVersionDelegate( ByRef Version As KLIB_VERSION) Public Delegate Function LibK_IsFunctionSupportedDelegate( <[In]> ByRef DriverAPI As KUSB_DRIVER_API, ByVal FunctionID As UInteger) As Boolean Public Delegate Function LibK_LoadDriverAPIDelegate( ByRef DriverAPI As KUSB_DRIVER_API, ByVal DriverID As Integer) As Boolean Public Delegate Function LibK_SetCleanupCallbackDelegate( <[In]> ByVal Handle As IntPtr, ByVal HandleType As KLIB_HANDLE_TYPE, ByVal CleanupCB As KLIB_HANDLE_CLEANUP_CB) As Boolean Public Delegate Function LibK_SetContextDelegate( <[In]> ByVal Handle As IntPtr, ByVal HandleType As KLIB_HANDLE_TYPE, ByVal ContextValue As IntPtr) As Boolean Public Delegate Function LibK_SetDefaultContextDelegate(ByVal HandleType As KLIB_HANDLE_TYPE, ByVal ContextValue As IntPtr) As Boolean Public Delegate Function LstK_CountDelegate( <[In]> ByVal DeviceList As KLST_HANDLE, ByRef Count As UInteger) As Boolean Public Delegate Function LstK_CurrentDelegate( <[In]> ByVal DeviceList As KLST_HANDLE, ByRef DeviceInfo As KLST_DEVINFO_HANDLE) As Boolean Public Delegate Function LstK_EnumerateDelegate( <[In]> ByVal DeviceList As KLST_HANDLE, ByVal EnumDevListCB As KLST_ENUM_DEVINFO_CB, ByVal Context As IntPtr) As Boolean Public Delegate Function LstK_FindByVidPidDelegate( <[In]> ByVal DeviceList As KLST_HANDLE, ByVal Vid As Integer, ByVal Pid As Integer, ByRef DeviceInfo As KLST_DEVINFO_HANDLE) As Boolean Public Delegate Function LstK_FreeDelegate( <[In]> ByVal DeviceList As KLST_HANDLE) As Boolean Public Delegate Function LstK_InitDelegate( ByRef DeviceList As KLST_HANDLE, ByVal Flags As KLST_FLAG) As Boolean Public Delegate Function LstK_InitExDelegate( ByRef DeviceList As KLST_HANDLE, ByVal Flags As KLST_FLAG, <[In]> ByRef PatternMatch As KLST_PATTERN_MATCH) As Boolean Public Delegate Function LstK_MoveNextDelegate( <[In]> ByVal DeviceList As KLST_HANDLE, ByRef DeviceInfo As KLST_DEVINFO_HANDLE) As Boolean Public Delegate Sub LstK_MoveResetDelegate( <[In]> ByVal DeviceList As KLST_HANDLE) Public Delegate Function LUsb0_ControlTransferDelegate( <[In]> ByVal InterfaceHandle As KUSB_HANDLE, ByVal SetupPacket As WINUSB_SETUP_PACKET, ByVal Buffer As IntPtr, ByVal BufferLength As UInteger, ByRef LengthTransferred As UInteger, ByVal Overlapped As IntPtr) As Boolean Public Delegate Function LUsb0_SetConfigurationDelegate( <[In]> ByVal InterfaceHandle As KUSB_HANDLE, ByVal ConfigurationNumber As Byte) As Boolean Public Delegate Function OvlK_AcquireDelegate( ByRef OverlappedK As KOVL_HANDLE, <[In]> ByVal PoolHandle As KOVL_POOL_HANDLE) As Boolean Public Delegate Function OvlK_FreeDelegate( <[In]> ByVal PoolHandle As KOVL_POOL_HANDLE) As Boolean Public Delegate Function OvlK_GetEventHandleDelegate( <[In]> ByVal OverlappedK As KOVL_HANDLE) As IntPtr Public Delegate Function OvlK_InitDelegate( ByRef PoolHandle As KOVL_POOL_HANDLE, <[In]> ByVal UsbHandle As KUSB_HANDLE, ByVal MaxOverlappedCount As Integer, ByVal Flags As KOVL_POOL_FLAG) As Boolean Public Delegate Function OvlK_IsCompleteDelegate( <[In]> ByVal OverlappedK As KOVL_HANDLE) As Boolean Public Delegate Function OvlK_ReleaseDelegate( <[In]> ByVal OverlappedK As KOVL_HANDLE) As Boolean Public Delegate Function OvlK_ReUseDelegate( <[In]> ByVal OverlappedK As KOVL_HANDLE) As Boolean Public Delegate Function OvlK_WaitAndReleaseDelegate( <[In]> ByVal OverlappedK As KOVL_HANDLE, ByVal TimeoutMS As Integer, ByRef TransferredLength As UInteger) As Boolean Public Delegate Function OvlK_WaitDelegate( <[In]> ByVal OverlappedK As KOVL_HANDLE, ByVal TimeoutMS As Integer, ByVal WaitFlags As KOVL_WAIT_FLAG, ByRef TransferredLength As UInteger) As Boolean Public Delegate Function OvlK_WaitOldestDelegate( <[In]> ByVal PoolHandle As KOVL_POOL_HANDLE, ByRef OverlappedK As KOVL_HANDLE, ByVal TimeoutMS As Integer, ByVal WaitFlags As KOVL_WAIT_FLAG, ByRef TransferredLength As UInteger) As Boolean Public Delegate Function OvlK_WaitOrCancelDelegate( <[In]> ByVal OverlappedK As KOVL_HANDLE, ByVal TimeoutMS As Integer, ByRef TransferredLength As UInteger) As Boolean Public Delegate Function StmK_FreeDelegate( <[In]> ByVal StreamHandle As KSTM_HANDLE) As Boolean Public Delegate Function StmK_InitDelegate( ByRef StreamHandle As KSTM_HANDLE, <[In]> ByVal UsbHandle As KUSB_HANDLE, ByVal PipeID As Byte, ByVal MaxTransferSize As Integer, ByVal MaxPendingTransfers As Integer, ByVal MaxPendingIO As Integer, <[In]> ByRef Callbacks As KSTM_CALLBACK, ByVal Flags As KSTM_FLAG) As Boolean Public Delegate Function StmK_ReadDelegate( <[In]> ByVal StreamHandle As KSTM_HANDLE, ByVal Buffer As IntPtr, ByVal Offset As Integer, ByVal Length As Integer, ByRef TransferredLength As UInteger) As Boolean Public Delegate Function StmK_StartDelegate( <[In]> ByVal StreamHandle As KSTM_HANDLE) As Boolean Public Delegate Function StmK_StopDelegate( <[In]> ByVal StreamHandle As KSTM_HANDLE, ByVal TimeoutCancelMS As Integer) As Boolean Public Delegate Function StmK_WriteDelegate( <[In]> ByVal StreamHandle As KSTM_HANDLE, ByVal Buffer As IntPtr, ByVal Offset As Integer, ByVal Length As Integer, ByRef TransferredLength As UInteger) As Boolean Public Delegate Function UsbK_FreeDelegate( <[In]> ByVal InterfaceHandle As KUSB_HANDLE) As Boolean Private ReadOnly mModuleLibusbK As IntPtr = IntPtr.Zero Public LibK_GetVersion As LibK_GetVersionDelegate Public LibK_GetContext As LibK_GetContextDelegate Public LibK_SetContext As LibK_SetContextDelegate Public LibK_SetCleanupCallback As LibK_SetCleanupCallbackDelegate Public LibK_LoadDriverAPI As LibK_LoadDriverAPIDelegate Public LibK_IsFunctionSupported As LibK_IsFunctionSupportedDelegate Public LibK_CopyDriverAPI As LibK_CopyDriverAPIDelegate Public LibK_GetProcAddress As LibK_GetProcAddressDelegate Public LibK_SetDefaultContext As LibK_SetDefaultContextDelegate Public LibK_GetDefaultContext As LibK_GetDefaultContextDelegate Public LibK_Context_Init As LibK_Context_InitDelegate Public LibK_Context_Free As LibK_Context_FreeDelegate Public UsbK_Free As UsbK_FreeDelegate Public LstK_Init As LstK_InitDelegate Public LstK_InitEx As LstK_InitExDelegate Public LstK_Free As LstK_FreeDelegate Public LstK_Enumerate As LstK_EnumerateDelegate Public LstK_Current As LstK_CurrentDelegate Public LstK_MoveNext As LstK_MoveNextDelegate Public LstK_MoveReset As LstK_MoveResetDelegate Public LstK_FindByVidPid As LstK_FindByVidPidDelegate Public LstK_Count As LstK_CountDelegate Public HotK_Init As HotK_InitDelegate Public HotK_Free As HotK_FreeDelegate Public HotK_FreeAll As HotK_FreeAllDelegate Public OvlK_Acquire As OvlK_AcquireDelegate Public OvlK_Release As OvlK_ReleaseDelegate Public OvlK_Init As OvlK_InitDelegate Public OvlK_Free As OvlK_FreeDelegate Public OvlK_GetEventHandle As OvlK_GetEventHandleDelegate Public OvlK_Wait As OvlK_WaitDelegate Public OvlK_WaitOldest As OvlK_WaitOldestDelegate Public OvlK_WaitOrCancel As OvlK_WaitOrCancelDelegate Public OvlK_WaitAndRelease As OvlK_WaitAndReleaseDelegate Public OvlK_IsComplete As OvlK_IsCompleteDelegate Public OvlK_ReUse As OvlK_ReUseDelegate Public StmK_Init As StmK_InitDelegate Public StmK_Free As StmK_FreeDelegate Public StmK_Start As StmK_StartDelegate Public StmK_Stop As StmK_StopDelegate Public StmK_Read As StmK_ReadDelegate Public StmK_Write As StmK_WriteDelegate Public IsoK_Init As IsoK_InitDelegate Public IsoK_Free As IsoK_FreeDelegate Public IsoK_SetPackets As IsoK_SetPacketsDelegate Public IsoK_SetPacket As IsoK_SetPacketDelegate Public IsoK_GetPacket As IsoK_GetPacketDelegate Public IsoK_EnumPackets As IsoK_EnumPacketsDelegate Public IsoK_ReUse As IsoK_ReUseDelegate Public IsochK_Init As IsochK_InitDelegate Public IsochK_Free As IsochK_FreeDelegate Public IsochK_SetPacketOffsets As IsochK_SetPacketOffsetsDelegate Public IsochK_SetPacket As IsochK_SetPacketDelegate Public IsochK_GetPacket As IsochK_GetPacketDelegate Public IsochK_EnumPackets As IsochK_EnumPacketsDelegate Public IsochK_CalcPacketInformation As IsochK_CalcPacketInformationDelegate Public IsochK_GetNumberOfPackets As IsochK_GetNumberOfPacketsDelegate Public IsochK_SetNumberOfPackets As IsochK_SetNumberOfPacketsDelegate Public LUsb0_ControlTransfer As LUsb0_ControlTransferDelegate Public LUsb0_SetConfiguration As LUsb0_SetConfigurationDelegate Sub New() If String.IsNullOrEmpty(LIBUSBK_FULLPATH_TO_ALTERNATE_DLL) Then mModuleLibusbK = LoadLibraryEx(LIBUSBK_DLL, IntPtr.Zero, LoadLibraryFlags.NONE) Else mModuleLibusbK = LoadLibraryEx(LIBUSBK_FULLPATH_TO_ALTERNATE_DLL, IntPtr.Zero, LoadLibraryFlags.LOAD_WITH_ALTERED_SEARCH_PATH) End If If mModuleLibusbK = IntPtr.Zero Then Throw New DllNotFoundException("libusbK.dll not found. Please install drivers/applications and retry.") Call LoadDynamicFunctions() End Sub Private Function LoadLibraryEx(ByVal lpFileName As String, ByVal hReservedNull As IntPtr, ByVal dwFlags As LoadLibraryFlags) As IntPtr End Function Private Function GetProcAddress(ByVal hModule As IntPtr, ByVal procName As String) As IntPtr End Function Private Sub LoadDynamicFunctions() LibK_GetVersion = CType(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "LibK_GetVersion"), GetType(LibK_GetVersionDelegate)), LibK_GetVersionDelegate) LibK_GetContext = CType(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "LibK_GetContext"), GetType(LibK_GetContextDelegate)), LibK_GetContextDelegate) LibK_SetContext = CType(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "LibK_SetContext"), GetType(LibK_SetContextDelegate)), LibK_SetContextDelegate) LibK_SetCleanupCallback = CType(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "LibK_SetCleanupCallback"), GetType(LibK_SetCleanupCallbackDelegate)), LibK_SetCleanupCallbackDelegate) LibK_LoadDriverAPI = CType(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "LibK_LoadDriverAPI"), GetType(LibK_LoadDriverAPIDelegate)), LibK_LoadDriverAPIDelegate) LibK_IsFunctionSupported = CType(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "LibK_IsFunctionSupported"), GetType(LibK_IsFunctionSupportedDelegate)), LibK_IsFunctionSupportedDelegate) LibK_CopyDriverAPI = CType(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "LibK_CopyDriverAPI"), GetType(LibK_CopyDriverAPIDelegate)), LibK_CopyDriverAPIDelegate) LibK_GetProcAddress = CType(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "LibK_GetProcAddress"), GetType(LibK_GetProcAddressDelegate)), LibK_GetProcAddressDelegate) LibK_SetDefaultContext = CType(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "LibK_SetDefaultContext"), GetType(LibK_SetDefaultContextDelegate)), LibK_SetDefaultContextDelegate) LibK_GetDefaultContext = CType(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "LibK_GetDefaultContext"), GetType(LibK_GetDefaultContextDelegate)), LibK_GetDefaultContextDelegate) LibK_Context_Init = CType(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "LibK_Context_Init"), GetType(LibK_Context_InitDelegate)), LibK_Context_InitDelegate) LibK_Context_Free = CType(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "LibK_Context_Free"), GetType(LibK_Context_FreeDelegate)), LibK_Context_FreeDelegate) UsbK_Free = CType(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "UsbK_Free"), GetType(UsbK_FreeDelegate)), UsbK_FreeDelegate) LstK_Init = CType(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "LstK_Init"), GetType(LstK_InitDelegate)), LstK_InitDelegate) LstK_InitEx = CType(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "LstK_InitEx"), GetType(LstK_InitExDelegate)), LstK_InitExDelegate) LstK_Free = CType(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "LstK_Free"), GetType(LstK_FreeDelegate)), LstK_FreeDelegate) LstK_Enumerate = CType(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "LstK_Enumerate"), GetType(LstK_EnumerateDelegate)), LstK_EnumerateDelegate) LstK_Current = CType(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "LstK_Current"), GetType(LstK_CurrentDelegate)), LstK_CurrentDelegate) LstK_MoveNext = CType(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "LstK_MoveNext"), GetType(LstK_MoveNextDelegate)), LstK_MoveNextDelegate) LstK_MoveReset = CType(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "LstK_MoveReset"), GetType(LstK_MoveResetDelegate)), LstK_MoveResetDelegate) LstK_FindByVidPid = CType(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "LstK_FindByVidPid"), GetType(LstK_FindByVidPidDelegate)), LstK_FindByVidPidDelegate) LstK_Count = CType(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "LstK_Count"), GetType(LstK_CountDelegate)), LstK_CountDelegate) HotK_Init = CType(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "HotK_Init"), GetType(HotK_InitDelegate)), HotK_InitDelegate) HotK_Free = CType(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "HotK_Free"), GetType(HotK_FreeDelegate)), HotK_FreeDelegate) HotK_FreeAll = CType(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "HotK_FreeAll"), GetType(HotK_FreeAllDelegate)), HotK_FreeAllDelegate) OvlK_Acquire = CType(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "OvlK_Acquire"), GetType(OvlK_AcquireDelegate)), OvlK_AcquireDelegate) OvlK_Release = CType(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "OvlK_Release"), GetType(OvlK_ReleaseDelegate)), OvlK_ReleaseDelegate) OvlK_Init = CType(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "OvlK_Init"), GetType(OvlK_InitDelegate)), OvlK_InitDelegate) OvlK_Free = CType(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "OvlK_Free"), GetType(OvlK_FreeDelegate)), OvlK_FreeDelegate) OvlK_GetEventHandle = CType(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "OvlK_GetEventHandle"), GetType(OvlK_GetEventHandleDelegate)), OvlK_GetEventHandleDelegate) OvlK_Wait = CType(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "OvlK_Wait"), GetType(OvlK_WaitDelegate)), OvlK_WaitDelegate) OvlK_WaitOldest = CType(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "OvlK_WaitOldest"), GetType(OvlK_WaitOldestDelegate)), OvlK_WaitOldestDelegate) OvlK_WaitOrCancel = CType(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "OvlK_WaitOrCancel"), GetType(OvlK_WaitOrCancelDelegate)), OvlK_WaitOrCancelDelegate) OvlK_WaitAndRelease = CType(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "OvlK_WaitAndRelease"), GetType(OvlK_WaitAndReleaseDelegate)), OvlK_WaitAndReleaseDelegate) OvlK_IsComplete = CType(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "OvlK_IsComplete"), GetType(OvlK_IsCompleteDelegate)), OvlK_IsCompleteDelegate) OvlK_ReUse = CType(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "OvlK_ReUse"), GetType(OvlK_ReUseDelegate)), OvlK_ReUseDelegate) StmK_Init = CType(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "StmK_Init"), GetType(StmK_InitDelegate)), StmK_InitDelegate) StmK_Free = CType(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "StmK_Free"), GetType(StmK_FreeDelegate)), StmK_FreeDelegate) StmK_Start = CType(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "StmK_Start"), GetType(StmK_StartDelegate)), StmK_StartDelegate) StmK_Stop = CType(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "StmK_Stop"), GetType(StmK_StopDelegate)), StmK_StopDelegate) StmK_Read = CType(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "StmK_Read"), GetType(StmK_ReadDelegate)), StmK_ReadDelegate) StmK_Write = CType(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "StmK_Write"), GetType(StmK_WriteDelegate)), StmK_WriteDelegate) IsoK_Init = CType(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "IsoK_Init"), GetType(IsoK_InitDelegate)), IsoK_InitDelegate) IsoK_Free = CType(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "IsoK_Free"), GetType(IsoK_FreeDelegate)), IsoK_FreeDelegate) IsoK_SetPackets = CType(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "IsoK_SetPackets"), GetType(IsoK_SetPacketsDelegate)), IsoK_SetPacketsDelegate) IsoK_SetPacket = CType(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "IsoK_SetPacket"), GetType(IsoK_SetPacketDelegate)), IsoK_SetPacketDelegate) IsoK_GetPacket = CType(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "IsoK_GetPacket"), GetType(IsoK_GetPacketDelegate)), IsoK_GetPacketDelegate) IsoK_EnumPackets = CType(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "IsoK_EnumPackets"), GetType(IsoK_EnumPacketsDelegate)), IsoK_EnumPacketsDelegate) IsoK_ReUse = CType(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "IsoK_ReUse"), GetType(IsoK_ReUseDelegate)), IsoK_ReUseDelegate) IsochK_Init = CType(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "IsochK_Init"), GetType(IsochK_InitDelegate)), IsochK_InitDelegate) IsochK_Free = CType(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "IsochK_Free"), GetType(IsochK_FreeDelegate)), IsochK_FreeDelegate) IsochK_SetPacketOffsets = CType(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "IsochK_SetPacketOffsets"), GetType(IsochK_SetPacketOffsetsDelegate)), IsochK_SetPacketOffsetsDelegate) IsochK_SetPacket = CType(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "IsochK_SetPacket"), GetType(IsochK_SetPacketDelegate)), IsochK_SetPacketDelegate) IsochK_GetPacket = CType(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "IsochK_GetPacket"), GetType(IsochK_GetPacketDelegate)), IsochK_GetPacketDelegate) IsochK_EnumPackets = CType(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "IsochK_EnumPackets"), GetType(IsochK_EnumPacketsDelegate)), IsochK_EnumPacketsDelegate) IsochK_CalcPacketInformation = CType(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "IsochK_CalcPacketInformation"), GetType(IsochK_CalcPacketInformationDelegate)), IsochK_CalcPacketInformationDelegate) IsochK_GetNumberOfPackets = CType(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "IsochK_GetNumberOfPackets"), GetType(IsochK_GetNumberOfPacketsDelegate)), IsochK_GetNumberOfPacketsDelegate) IsochK_SetNumberOfPackets = CType(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "IsochK_SetNumberOfPackets"), GetType(IsochK_SetNumberOfPacketsDelegate)), IsochK_SetNumberOfPacketsDelegate) LUsb0_ControlTransfer = CType(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "LUsb0_ControlTransfer"), GetType(LUsb0_ControlTransferDelegate)), LUsb0_ControlTransferDelegate) LUsb0_SetConfiguration = CType(Marshal.GetDelegateForFunctionPointer(GetProcAddress(mModuleLibusbK, "LUsb0_SetConfiguration"), GetType(LUsb0_SetConfigurationDelegate)), LUsb0_SetConfigurationDelegate) End Sub Friend Enum LoadLibraryFlags NONE = 0 DONT_RESOLVE_DLL_REFERENCES = &H00000001 LOAD_IGNORE_CODE_AUTHZ_LEVEL = &H00000010 LOAD_LIBRARY_AS_DATAFILE = &H00000002 LOAD_LIBRARY_AS_DATAFILE_EXCLUSIVE = &H00000040 LOAD_LIBRARY_AS_IMAGE_RESOURCE = &H00000020 LOAD_WITH_ALTERED_SEARCH_PATH = &H00000008 End Enum End Module #End Region #Region "Enumerations" ''' Values used in the \c bmAttributes field of a \ref USB_ENDPOINT_DESCRIPTOR Public Enum USBD_PIPE_TYPE ''' Indicates a control endpoint UsbdPipeTypeControl ''' Indicates an isochronous endpoint UsbdPipeTypeIsochronous ''' Indicates a bulk endpoint UsbdPipeTypeBulk ''' Indicates an interrupt endpoint UsbdPipeTypeInterrupt End Enum ''' Additional ISO transfer flags. Public Enum KISO_FLAG NONE = 0 ''' Do not start the transfer immediately, instead use \ref KISO_CONTEXT::StartFrame. SET_START_FRAME = &H00000001 End Enum ''' Handle type enumeration. Public Enum KLIB_HANDLE_TYPE ''' Hot plug handle. \ref KHOT_HANDLE HOTK ''' USB handle. \ref KUSB_HANDLE USBK ''' Shared USB handle. \ref KUSB_HANDLE USBSHAREDK ''' Device list handle. \ref KLST_HANDLE LSTK ''' Device info handle. \ref KLST_DEVINFO_HANDLE LSTINFOK ''' Overlapped handle. \ref KOVL_HANDLE OVLK ''' Overlapped pool handle. \ref KOVL_POOL_HANDLE OVLPOOLK ''' Pipe stream handle. \ref KSTM_HANDLE STMK ''' Pipe stream handle. \ref KSTM_HANDLE ISOCHK ''' Max handle type count. COUNT End Enum ''' Device list sync flags. Public Enum KLST_SYNC_FLAG ''' Cleared/invalid state. NONE = 0 ''' Unchanged state, UNCHANGED = &H0001 ''' Added (Arrival) state, ADDED = &H0002 ''' Removed (Unplugged) state, REMOVED = &H0004 ''' Connect changed state. CONNECT_CHANGE = &H0008 ''' All states. MASK = &H000F End Enum ''' Device list initialization flags. Public Enum KLST_FLAG ''' No flags (or 0) NONE = 0 ''' Enable listings for the raw device interface GUID \b only. {A5DCBF10-6530-11D2-901F-00C04FB951ED} INCLUDE_RAWGUID = &H0001 ''' List all libusbK devices including those not currently connected. INCLUDE_DISCONNECT = &H0002 End Enum ''' bmRequest.Dir Public Enum BMREQUEST_DIR HOST_TO_DEVICE = 0 DEVICE_TO_HOST = 1 End Enum ''' bmRequest.Type Public Enum BMREQUEST_TYPE ''' Standard request. See \ref USB_REQUEST_ENUM STANDARD = 0 ''' Class-specific request. [CLASS] = 1 ''' Vendor-specific request VENDOR = 2 End Enum ''' bmRequest.Recipient Public Enum BMREQUEST_RECIPIENT ''' Request is for a device. DEVICE = 0 ''' Request is for an interface of a device. [INTERFACE] = 1 ''' Request is for an endpoint of a device. ENDPOINT = 2 ''' Request is for a vendor-specific purpose. OTHER = 3 End Enum ''' Values for the bits returned by the \ref USB_REQUEST_GET_STATUS request. Public Enum USB_GETSTATUS ''' Device is self powered SELF_POWERED = &H01 ''' Device can wake the system from a low power/sleeping state. REMOTE_WAKEUP_ENABLED = &H02 End Enum ''' Standard USB descriptor types. For more information, see section 9-5 of the USB 3.0 specifications. Public Enum USB_DESCRIPTOR_TYPE ''' Device descriptor type. DEVICE = &H01 ''' Configuration descriptor type. CONFIGURATION = &H02 ''' String descriptor type. [STRING] = &H03 ''' Interface descriptor type. [INTERFACE] = &H04 ''' Endpoint descriptor type. ENDPOINT = &H05 ''' Device qualifier descriptor type. DEVICE_QUALIFIER = &H06 ''' Config power descriptor type. CONFIG_POWER = &H07 ''' Interface power descriptor type. INTERFACE_POWER = &H08 ''' Interface association descriptor type. INTERFACE_ASSOCIATION = &H0B USB_SUPERSPEED_ENDPOINT_COMPANION = &H30 End Enum ''' Usb handle specific properties that can be retrieved with \ref UsbK_GetProperty. Public Enum KUSB_PROPERTY ''' Get the internal device file handle used for operations such as GetOverlappedResult or DeviceIoControl. DEVICE_FILE_HANDLE COUNT End Enum ''' Supported driver id enumeration. Public Enum KUSB_DRVID ''' libusbK.sys driver ID LIBUSBK ''' libusb0.sys driver ID LIBUSB0 ''' WinUSB.sys driver ID WINUSB ''' libusb0.sys filter driver ID LIBUSB0_FILTER ''' Supported driver count COUNT End Enum ''' Supported function id enumeration. Public Enum KUSB_FNID ''' \ref UsbK_Init dynamic driver function id. Init ''' \ref UsbK_Free dynamic driver function id. Free ''' \ref UsbK_ClaimInterface dynamic driver function id. ClaimInterface ''' \ref UsbK_ReleaseInterface dynamic driver function id. ReleaseInterface ''' \ref UsbK_SetAltInterface dynamic driver function id. SetAltInterface ''' \ref UsbK_GetAltInterface dynamic driver function id. GetAltInterface ''' \ref UsbK_GetDescriptor dynamic driver function id. GetDescriptor ''' \ref UsbK_ControlTransfer dynamic driver function id. ControlTransfer ''' \ref UsbK_SetPowerPolicy dynamic driver function id. SetPowerPolicy ''' \ref UsbK_GetPowerPolicy dynamic driver function id. GetPowerPolicy ''' \ref UsbK_SetConfiguration dynamic driver function id. SetConfiguration ''' \ref UsbK_GetConfiguration dynamic driver function id. GetConfiguration ''' \ref UsbK_ResetDevice dynamic driver function id. ResetDevice ''' \ref UsbK_Initialize dynamic driver function id. Initialize ''' \ref UsbK_SelectInterface dynamic driver function id. SelectInterface ''' \ref UsbK_GetAssociatedInterface dynamic driver function id. GetAssociatedInterface ''' \ref UsbK_Clone dynamic driver function id. Clone ''' \ref UsbK_QueryInterfaceSettings dynamic driver function id. QueryInterfaceSettings ''' \ref UsbK_QueryDeviceInformation dynamic driver function id. QueryDeviceInformation ''' \ref UsbK_SetCurrentAlternateSetting dynamic driver function id. SetCurrentAlternateSetting ''' \ref UsbK_GetCurrentAlternateSetting dynamic driver function id. GetCurrentAlternateSetting ''' \ref UsbK_QueryPipe dynamic driver function id. QueryPipe ''' \ref UsbK_SetPipePolicy dynamic driver function id. SetPipePolicy ''' \ref UsbK_GetPipePolicy dynamic driver function id. GetPipePolicy ''' \ref UsbK_ReadPipe dynamic driver function id. ReadPipe ''' \ref UsbK_WritePipe dynamic driver function id. WritePipe ''' \ref UsbK_ResetPipe dynamic driver function id. ResetPipe ''' \ref UsbK_AbortPipe dynamic driver function id. AbortPipe ''' \ref UsbK_FlushPipe dynamic driver function id. FlushPipe ''' \ref UsbK_IsoReadPipe dynamic driver function id. IsoReadPipe ''' \ref UsbK_IsoWritePipe dynamic driver function id. IsoWritePipe ''' \ref UsbK_GetCurrentFrameNumber dynamic driver function id. GetCurrentFrameNumber ''' \ref UsbK_GetOverlappedResult dynamic driver function id. GetOverlappedResult ''' \ref UsbK_GetProperty dynamic driver function id. GetProperty ''' \ref UsbK_IsochReadPipe dynamic driver function id. IsochReadPipe ''' \ref UsbK_IsochWritePipe dynamic driver function id. IsochWritePipe ''' \ref UsbK_QueryPipeEx dynamic driver function id. QueryPipeEx ''' \ref UsbK_GetSuperSpeedPipeCompanionDescriptor dynamic driver function id. GetSuperSpeedPipeCompanionDescriptor ''' Supported function count COUNT End Enum ''' Hot plug config flags. Public Enum KHOT_FLAG ''' No flags (or 0) NONE ''' Notify all devices which match upon a succuessful call to \ref HotK_Init. PLUG_ALL_ON_INIT = &H0001 ''' Allow other \ref KHOT_HANDLE instances to consume this match. PASS_DUPE_INSTANCE = &H0002 ''' If a \c UserHwnd is specified, use \c PostMessage instead of \c SendMessage. POST_USER_MESSAGE = &H0004 End Enum ''' \c WaitFlags used by \ref OvlK_Wait. Public Enum KOVL_WAIT_FLAG ''' Do not perform any additional actions upon exiting \ref OvlK_Wait. NONE = 0 ''' If the i/o operation completes successfully, release the OverlappedK back to it's pool. RELEASE_ON_SUCCESS = &H0001 ''' If the i/o operation fails, release the OverlappedK back to it's pool. RELEASE_ON_FAIL = &H0002 ''' ''' If the i/o operation fails or completes successfully, release the OverlappedK back to its pool. Perform no ''' actions if it times-out. ''' RELEASE_ON_SUCCESS_FAIL = &H0003 ''' If the i/o operation times-out cancel it, but do not release the OverlappedK back to its pool. CANCEL_ON_TIMEOUT = &H0004 ''' If the i/o operation times-out, cancel it and release the OverlappedK back to its pool. RELEASE_ON_TIMEOUT = &H000C ''' ''' Always release the OverlappedK back to its pool. If the operation timed-out, cancel it before releasing back ''' to its pool. ''' RELEASE_ALWAYS = &H000F ''' ''' Uses alterable wait functions. See ''' http://msdn.microsoft.com/en-us/library/windows/desktop/ms687036%28v=vs.85%29.aspx ''' ALERTABLE = &H0010 End Enum ''' \c Overlapped pool config flags. Public Enum KOVL_POOL_FLAG NONE = 0 End Enum ''' Stream config flags. Public Enum KSTM_FLAG As UInteger ''' None NONE = 0 NO_PARTIAL_XFERS = &H00100000 USE_TIMEOUT = &H80000000UI TIMEOUT_MASK = &H0001FFFF End Enum ''' Stream config flags. Public Enum KSTM_COMPLETE_RESULT ''' Valid VALID = 0 ''' Invalid INVALID End Enum #End Region #Region "Structs" ''' ''' The \c WINUSB_PIPE_INFORMATION structure contains pipe information that the \ref UsbK_QueryPipe routine ''' retrieves. ''' Public Structure WINUSB_PIPE_INFORMATION ''' A \c USBD_PIPE_TYPE enumeration value that specifies the pipe type Public PipeType As USBD_PIPE_TYPE ''' The pipe identifier (ID) Public PipeId As Byte ''' The maximum size, in bytes, of the packets that are transmitted on the pipe Public MaximumPacketSize As UShort ''' The pipe interval Public Interval As Byte Public Overrides Function ToString() As String Return String.Format("PipeType: {0}" & Microsoft.VisualBasic.Constants.vbLf & "PipeId: {1}" & Microsoft.VisualBasic.Constants.vbLf & "MaximumPacketSize: {2}" & Microsoft.VisualBasic.Constants.vbLf & "Interval: {3}" & Microsoft.VisualBasic.Constants.vbLf, PipeType, PipeId.ToString("X2") & "h", MaximumPacketSize, Interval.ToString("X2") & "h") End Function End Structure ''' ''' The \c WINUSB_PIPE_INFORMATION_EX structure contains pipe information that the \ref UsbK_QueryPipeEx routine ''' retrieves. ''' Public Structure WINUSB_PIPE_INFORMATION_EX ''' A \c USBD_PIPE_TYPE enumeration value that specifies the pipe type Public PipeType As USBD_PIPE_TYPE ''' The pipe identifier (ID) Public PipeId As Byte ''' The maximum size, in bytes, of the packets that are transmitted on the pipe Public MaximumPacketSize As UShort ''' The pipe interval Public Interval As Byte ''' The maximum number of bytes that can be transmitted in single interval. Public MaximumBytesPerInterval As UInteger Public Overrides Function ToString() As String Return String.Format("PipeType: {0}" & Microsoft.VisualBasic.Constants.vbLf & "PipeId: {1}" & Microsoft.VisualBasic.Constants.vbLf & "MaximumPacketSize: {2}" & Microsoft.VisualBasic.Constants.vbLf & "Interval: {3}" & Microsoft.VisualBasic.Constants.vbLf & "MaximumBytesPerInterval: {4}" & Microsoft.VisualBasic.Constants.vbLf, PipeType, PipeId.ToString("X2") & "h", MaximumPacketSize, Interval.ToString("X2") & "h", MaximumBytesPerInterval) End Function End Structure ''' The \c WINUSB_SETUP_PACKET structure describes a USB setup packet. Public Structure WINUSB_SETUP_PACKET ''' ''' The request type. The values that are assigned to this member are defined in Table 9.2 of section 9.3 of the ''' Universal Serial Bus (USB) specification (www.usb.org). ''' Public RequestType As Byte ''' ''' The device request. The values that are assigned to this member are defined in Table 9.3 of section 9.4 of the ''' Universal Serial Bus (USB) specification. ''' Public Request As Byte ''' ''' The meaning of this member varies according to the request. For an explanation of this member, see the ''' Universal Serial Bus (USB) specification. ''' Public Value As UShort ''' ''' The meaning of this member varies according to the request. For an explanation of this member, see the ''' Universal Serial Bus (USB) specification. ''' Public Index As UShort ''' The number of bytes to transfer. (not including the \c WINUSB_SETUP_PACKET itself) Public Length As UShort Public Overrides Function ToString() As String Return String.Format("RequestType: {0}" & Microsoft.VisualBasic.Constants.vbLf & "Request: {1}" & Microsoft.VisualBasic.Constants.vbLf & "Value: {2}" & Microsoft.VisualBasic.Constants.vbLf & "Index: {3}" & Microsoft.VisualBasic.Constants.vbLf & "Length: {4}" & Microsoft.VisualBasic.Constants.vbLf, RequestType.ToString("X2") & "h", Request.ToString("X2") & "h", Value.ToString("X4") & "h", Index.ToString("X4") & "h", Length) End Function End Structure ''' Structure describing an isochronous transfer packet for libusbK. Public Structure KISO_PACKET ''' ''' Specifies the offset, in bytes, of the buffer for this packet from the beginning of the entire isochronous ''' transfer data buffer. ''' Public Offset As UInteger ''' ''' Set by the host controller to indicate the actual number of bytes received by the device for isochronous IN ''' transfers. Length not used for isochronous OUT transfers. ''' Public Length As UShort ''' ''' Contains the 16 least significant USBD status bits, on return from the host controller driver, of this ''' transfer packet. ''' Public Status As UShort Public Overrides Function ToString() As String Return String.Format("Offset: {0}" & Microsoft.VisualBasic.Constants.vbLf & "Length: {1}" & Microsoft.VisualBasic.Constants.vbLf & "Status: {2}" & Microsoft.VisualBasic.Constants.vbLf, Offset, Length, Status.ToString("X4") & "h") End Function End Structure ''' Structure describing an isochronous transfer packet for winusb. Public Structure KISO_WUSB_PACKET ''' ''' Specifies the offset, in bytes, of the buffer for this packet from the beginning of the entire isochronous ''' transfer data buffer. ''' Public Offset As UInteger ''' ''' Set by the host controller to indicate the actual number of bytes received by the device for isochronous IN ''' transfers. Length not used for isochronous OUT transfers. ''' Public Length As UInteger ''' ''' Contains the 16 least significant USBD status bits, on return from the host controller driver, of this ''' transfer packet. ''' Public Status As UInteger Public Overrides Function ToString() As String Return String.Format("Offset: {0}" & Microsoft.VisualBasic.Constants.vbLf & "Length: {1}" & Microsoft.VisualBasic.Constants.vbLf & "Status: {2}" & Microsoft.VisualBasic.Constants.vbLf, Offset, Length, Status) End Function End Structure Public Structure KISO_CONTEXT Private ReadOnly mHandlePtr As IntPtr Public Sub New(ByVal Handle As IntPtr) mHandlePtr = Handle End Sub Public ReadOnly Property Pointer As IntPtr Get Return mHandlePtr End Get End Property ''' KISO_CONTEXT_MAP is used for calculating field offsets only Private Structure KISO_CONTEXT_MAP ''' Additional ISO transfer flags. See \ref KISO_FLAG. Private ReadOnly Flags As KISO_FLAG ''' Specifies the frame number that the transfer should begin on (0 for ASAP). Private ReadOnly StartFrame As UInteger ''' ''' Contains the number of packets that completed with an error condition on return from the host controller ''' driver. ''' Private ReadOnly ErrorCount As Short ''' Specifies the number of packets that are described by the variable-length array member \c IsoPacket. Private ReadOnly NumberOfPackets As Short ''' Contains the URB Hdr.Status value on return from the host controller driver. Private ReadOnly UrbHdrStatus As UInteger End Structure Private Shared ReadOnly ofsFlags As Integer = Marshal.OffsetOf(GetType(KISO_CONTEXT_MAP), "Flags").ToInt32() Private Shared ReadOnly ofsStartFrame As Integer = Marshal.OffsetOf(GetType(KISO_CONTEXT_MAP), "StartFrame").ToInt32() Private Shared ReadOnly ofsErrorCount As Integer = Marshal.OffsetOf(GetType(KISO_CONTEXT_MAP), "ErrorCount").ToInt32() Private Shared ReadOnly ofsNumberOfPackets As Integer = Marshal.OffsetOf(GetType(KISO_CONTEXT_MAP), "NumberOfPackets").ToInt32() Private Shared ReadOnly ofsUrbHdrStatus As Integer = Marshal.OffsetOf(GetType(KISO_CONTEXT_MAP), "UrbHdrStatus").ToInt32() ''' Additional ISO transfer flags. See \ref KISO_FLAG. Public ReadOnly Property Flags As KISO_FLAG Get Return Marshal.ReadInt32(mHandlePtr, ofsFlags) End Get End Property ''' Specifies the frame number that the transfer should begin on (0 for ASAP). Public ReadOnly Property StartFrame As UInteger Get Return Marshal.ReadInt32(mHandlePtr, ofsStartFrame) End Get End Property ''' ''' Contains the number of packets that completed with an error condition on return from the host controller ''' driver. ''' Public ReadOnly Property ErrorCount As Short Get Return Marshal.ReadInt16(mHandlePtr, ofsErrorCount) End Get End Property ''' Specifies the number of packets that are described by the variable-length array member \c IsoPacket. Public ReadOnly Property NumberOfPackets As Short Get Return Marshal.ReadInt16(mHandlePtr, ofsNumberOfPackets) End Get End Property ''' Contains the URB Hdr.Status value on return from the host controller driver. Public ReadOnly Property UrbHdrStatus As UInteger Get Return Marshal.ReadInt32(mHandlePtr, ofsUrbHdrStatus) End Get End Property Public Overrides Function ToString() As String Return String.Format("Flags: {0}" & Microsoft.VisualBasic.Constants.vbLf & "StartFrame: {1}" & Microsoft.VisualBasic.Constants.vbLf & "ErrorCount: {2}" & Microsoft.VisualBasic.Constants.vbLf & "NumberOfPackets: {3}" & Microsoft.VisualBasic.Constants.vbLf & "UrbHdrStatus: {4}" & Microsoft.VisualBasic.Constants.vbLf, Flags.ToString(), StartFrame, ErrorCount, NumberOfPackets, UrbHdrStatus.ToString("X8") & "h") End Function End Structure ''' Structure describing additional information about how an isochronous pipe transfers data. Public Structure KISOCH_PACKET_INFORMATION ''' Number of ISO packets transferred per whole USB frame (1 millisecond). Public PacketsPerFrame As UInteger ''' How often a pipe transfers data. Public PollingPeriodMicroseconds As UInteger ''' Number of bytes transferred per millisecond (or whole frame). Public BytesPerMillisecond As UInteger Public Overrides Function ToString() As String Return String.Format("PacketsPerFrame: {0}" & Microsoft.VisualBasic.Constants.vbLf & "PollingPeriodMicroseconds: {1}" & Microsoft.VisualBasic.Constants.vbLf & "BytesPerMillisecond: {2}" & Microsoft.VisualBasic.Constants.vbLf, PacketsPerFrame, PollingPeriodMicroseconds, BytesPerMillisecond) End Function End Structure ''' libusbK verson information structure. Public Structure KLIB_VERSION ''' Major version number. Public Major As Integer ''' Minor version number. Public Minor As Integer ''' Micro version number. Public Micro As Integer ''' Nano version number. Public Nano As Integer Public Overrides Function ToString() As String Return String.Format("Major: {0}" & Microsoft.VisualBasic.Constants.vbLf & "Minor: {1}" & Microsoft.VisualBasic.Constants.vbLf & "Micro: {2}" & Microsoft.VisualBasic.Constants.vbLf & "Nano: {3}" & Microsoft.VisualBasic.Constants.vbLf, Major, Minor, Micro, Nano) End Function End Structure ''' Common usb device information structure Public Structure KLST_DEV_COMMON_INFO ''' VendorID parsed from \ref KLST_DEVINFO::DeviceID Public Vid As Integer ''' ProductID parsed from \ref KLST_DEVINFO::DeviceID Public Pid As Integer ''' ''' Composite interface number parsed from \ref KLST_DEVINFO::DeviceID. Set to \b -1 for devices that do not have ''' the composite parent driver. ''' Public MI As Integer ' An ID that uniquely identifies a USB device. Public InstanceID As String Public Overrides Function ToString() As String Return String.Format("Vid: {0}" & Microsoft.VisualBasic.Constants.vbLf & "Pid: {1}" & Microsoft.VisualBasic.Constants.vbLf & "MI: {2}" & Microsoft.VisualBasic.Constants.vbLf & "InstanceID: {3}" & Microsoft.VisualBasic.Constants.vbLf, Vid.ToString("X4") & "h", Pid.ToString("X4") & "h", MI.ToString("X2") & "h", InstanceID) End Function End Structure Public Structure KLST_DEVINFO_HANDLE Implements IKLIB_HANDLE Private ReadOnly mHandlePtr As IntPtr Public Sub New(ByVal Handle As IntPtr) mHandlePtr = Handle End Sub Public ReadOnly Property Pointer As IntPtr Implements IKLIB_HANDLE.Pointer Get Return mHandlePtr End Get End Property Public ReadOnly Property HandleType As KLIB_HANDLE_TYPE Implements IKLIB_HANDLE.HandleType Get Return KLIB_HANDLE_TYPE.LSTINFOK End Get End Property Public Function GetContext() As IntPtr Implements IKLIB_HANDLE.GetContext Return LibK_GetContext(mHandlePtr, HandleType) End Function Public Function SetContext(ByVal UserContext As IntPtr) As Boolean Implements IKLIB_HANDLE.SetContext Return LibK_SetContext(mHandlePtr, HandleType, UserContext) End Function Public Function SetCleanupCallback(ByVal CleanupCallback As KLIB_HANDLE_CLEANUP_CB) As Boolean Implements IKLIB_HANDLE.SetCleanupCallback Return LibK_SetCleanupCallback(mHandlePtr, HandleType, CleanupCallback) End Function ''' KLST_DEVINFO_MAP is used for calculating field offsets only Private Structure KLST_DEVINFO_MAP ''' Common usb device information Private ReadOnly Common As KLST_DEV_COMMON_INFO ''' Driver id this device element is using Private ReadOnly DriverID As Integer ''' Device interface GUID Private ReadOnly DeviceInterfaceGUID As String ''' Device instance ID. Private ReadOnly DeviceID As String ''' Class GUID. Private ReadOnly ClassGUID As String ''' Manufacturer name as specified in the INF file. Private ReadOnly Mfg As String ''' Device description as specified in the INF file. Private ReadOnly DeviceDesc As String ''' Driver service name. Private ReadOnly Service As String ''' Unique identifier. Private ReadOnly SymbolicLink As String ''' physical device filename used with the Windows \c CreateFile() Private ReadOnly DevicePath As String ''' libusb-win32 filter index id. Private ReadOnly LUsb0FilterIndex As Integer ''' Indicates the devices connection state. Private ReadOnly Connected As Boolean ''' Synchronization flags. (internal use only) Private ReadOnly SyncFlags As KLST_SYNC_FLAG Private ReadOnly BusNumber As Integer Private ReadOnly DeviceAddress As Integer ''' ''' If the the device is serialized, represents the string value of \ref USB_DEVICE_DESCRIPTOR::iSerialNumber. For ''' Devices without a \b iSerialNumber, represents the unique \b InstanceID assigned by \b Windows. ''' Private ReadOnly SerialNumber As String End Structure Private Shared ReadOnly ofsCommon As Integer = Marshal.OffsetOf(GetType(KLST_DEVINFO_MAP), "Common").ToInt32() Private Shared ReadOnly ofsDriverID As Integer = Marshal.OffsetOf(GetType(KLST_DEVINFO_MAP), "DriverID").ToInt32() Private Shared ReadOnly ofsDeviceInterfaceGUID As Integer = Marshal.OffsetOf(GetType(KLST_DEVINFO_MAP), "DeviceInterfaceGUID").ToInt32() Private Shared ReadOnly ofsDeviceID As Integer = Marshal.OffsetOf(GetType(KLST_DEVINFO_MAP), "DeviceID").ToInt32() Private Shared ReadOnly ofsClassGUID As Integer = Marshal.OffsetOf(GetType(KLST_DEVINFO_MAP), "ClassGUID").ToInt32() Private Shared ReadOnly ofsMfg As Integer = Marshal.OffsetOf(GetType(KLST_DEVINFO_MAP), "Mfg").ToInt32() Private Shared ReadOnly ofsDeviceDesc As Integer = Marshal.OffsetOf(GetType(KLST_DEVINFO_MAP), "DeviceDesc").ToInt32() Private Shared ReadOnly ofsService As Integer = Marshal.OffsetOf(GetType(KLST_DEVINFO_MAP), "Service").ToInt32() Private Shared ReadOnly ofsSymbolicLink As Integer = Marshal.OffsetOf(GetType(KLST_DEVINFO_MAP), "SymbolicLink").ToInt32() Private Shared ReadOnly ofsDevicePath As Integer = Marshal.OffsetOf(GetType(KLST_DEVINFO_MAP), "DevicePath").ToInt32() Private Shared ReadOnly ofsLUsb0FilterIndex As Integer = Marshal.OffsetOf(GetType(KLST_DEVINFO_MAP), "LUsb0FilterIndex").ToInt32() Private Shared ReadOnly ofsConnected As Integer = Marshal.OffsetOf(GetType(KLST_DEVINFO_MAP), "Connected").ToInt32() Private Shared ReadOnly ofsSyncFlags As Integer = Marshal.OffsetOf(GetType(KLST_DEVINFO_MAP), "SyncFlags").ToInt32() Private Shared ReadOnly ofsBusNumber As Integer = Marshal.OffsetOf(GetType(KLST_DEVINFO_MAP), "BusNumber").ToInt32() Private Shared ReadOnly ofsDeviceAddress As Integer = Marshal.OffsetOf(GetType(KLST_DEVINFO_MAP), "DeviceAddress").ToInt32() Private Shared ReadOnly ofsSerialNumber As Integer = Marshal.OffsetOf(GetType(KLST_DEVINFO_MAP), "SerialNumber").ToInt32() ''' Common usb device information Public ReadOnly Property Common As KLST_DEV_COMMON_INFO Get Return CType(Marshal.PtrToStructure(New IntPtr(mHandlePtr.ToInt64() + ofsCommon), GetType(KLST_DEV_COMMON_INFO)), KLST_DEV_COMMON_INFO) End Get End Property ''' Driver id this device element is using Public ReadOnly Property DriverID As Integer Get Return Marshal.ReadInt32(mHandlePtr, ofsDriverID) End Get End Property ''' Device interface GUID Public ReadOnly Property DeviceInterfaceGUID As String Get Return Marshal.PtrToStringAnsi(New IntPtr(mHandlePtr.ToInt64() + ofsDeviceInterfaceGUID)) End Get End Property ''' Device instance ID. Public ReadOnly Property DeviceID As String Get Return Marshal.PtrToStringAnsi(New IntPtr(mHandlePtr.ToInt64() + ofsDeviceID)) End Get End Property ''' Class GUID. Public ReadOnly Property ClassGUID As String Get Return Marshal.PtrToStringAnsi(New IntPtr(mHandlePtr.ToInt64() + ofsClassGUID)) End Get End Property ''' Manufacturer name as specified in the INF file. Public ReadOnly Property Mfg As String Get Return Marshal.PtrToStringAnsi(New IntPtr(mHandlePtr.ToInt64() + ofsMfg)) End Get End Property ''' Device description as specified in the INF file. Public ReadOnly Property DeviceDesc As String Get Return Marshal.PtrToStringAnsi(New IntPtr(mHandlePtr.ToInt64() + ofsDeviceDesc)) End Get End Property ''' Driver service name. Public ReadOnly Property Service As String Get Return Marshal.PtrToStringAnsi(New IntPtr(mHandlePtr.ToInt64() + ofsService)) End Get End Property ''' Unique identifier. Public ReadOnly Property SymbolicLink As String Get Return Marshal.PtrToStringAnsi(New IntPtr(mHandlePtr.ToInt64() + ofsSymbolicLink)) End Get End Property ''' physical device filename used with the Windows \c CreateFile() Public ReadOnly Property DevicePath As String Get Return Marshal.PtrToStringAnsi(New IntPtr(mHandlePtr.ToInt64() + ofsDevicePath)) End Get End Property ''' libusb-win32 filter index id. Public ReadOnly Property LUsb0FilterIndex As Integer Get Return Marshal.ReadInt32(mHandlePtr, ofsLUsb0FilterIndex) End Get End Property ''' Indicates the devices connection state. Public ReadOnly Property Connected As Boolean Get Return Marshal.ReadInt32(mHandlePtr, ofsConnected) <> 0 End Get End Property ''' Synchronization flags. (internal use only) Public ReadOnly Property SyncFlags As KLST_SYNC_FLAG Get Return Marshal.ReadInt32(mHandlePtr, ofsSyncFlags) End Get End Property Public ReadOnly Property BusNumber As Integer Get Return Marshal.ReadInt32(mHandlePtr, ofsBusNumber) End Get End Property Public ReadOnly Property DeviceAddress As Integer Get Return Marshal.ReadInt32(mHandlePtr, ofsDeviceAddress) End Get End Property ''' ''' If the the device is serialized, represents the string value of \ref USB_DEVICE_DESCRIPTOR::iSerialNumber. For ''' Devices without a \b iSerialNumber, represents the unique \b InstanceID assigned by \b Windows. ''' Public ReadOnly Property SerialNumber As String Get Return Marshal.PtrToStringAnsi(New IntPtr(mHandlePtr.ToInt64() + ofsSerialNumber)) End Get End Property Public Overrides Function ToString() As String Return String.Format("DriverID: {0}" & Microsoft.VisualBasic.Constants.vbLf & "DeviceInterfaceGUID: {1}" & Microsoft.VisualBasic.Constants.vbLf & "DeviceID: {2}" & Microsoft.VisualBasic.Constants.vbLf & "ClassGUID: {3}" & Microsoft.VisualBasic.Constants.vbLf & "Mfg: {4}" & Microsoft.VisualBasic.Constants.vbLf & "DeviceDesc: {5}" & Microsoft.VisualBasic.Constants.vbLf & "Service: {6}" & Microsoft.VisualBasic.Constants.vbLf & "SymbolicLink: {7}" & Microsoft.VisualBasic.Constants.vbLf & "DevicePath: {8}" & Microsoft.VisualBasic.Constants.vbLf & "LUsb0FilterIndex: {9}" & Microsoft.VisualBasic.Constants.vbLf & "Connected: {10}" & Microsoft.VisualBasic.Constants.vbLf & "SyncFlags: {11}" & Microsoft.VisualBasic.Constants.vbLf & "BusNumber: {12}" & Microsoft.VisualBasic.Constants.vbLf & "DeviceAddress: {13}" & Microsoft.VisualBasic.Constants.vbLf & "SerialNumber: {14}" & Microsoft.VisualBasic.Constants.vbLf, DriverID, DeviceInterfaceGUID, DeviceID, ClassGUID, Mfg, DeviceDesc, Service, SymbolicLink, DevicePath, LUsb0FilterIndex, Connected, SyncFlags.ToString(), BusNumber, DeviceAddress, SerialNumber) End Function End Structure ''' Device list/hot-plug pattern match structure. Public Structure KLST_PATTERN_MATCH ''' Pattern match a device instance id. Public DeviceID As String ''' Pattern match a device interface guid. Public DeviceInterfaceGUID As String ''' Pattern match a symbolic link. Public ClassGUID As String Public Overrides Function ToString() As String Return String.Format("DeviceID: {0}" & Microsoft.VisualBasic.Constants.vbLf & "DeviceInterfaceGUID: {1}" & Microsoft.VisualBasic.Constants.vbLf & "ClassGUID: {2}" & Microsoft.VisualBasic.Constants.vbLf, DeviceID, DeviceInterfaceGUID, ClassGUID) End Function End Structure ''' A structure representing the standard USB device descriptor. Public Structure USB_DEVICE_DESCRIPTOR ''' Size of this descriptor (in bytes) Public bLength As Byte ''' Descriptor type Public bDescriptorType As Byte ''' USB specification release number in binary-coded decimal. Public bcdUSB As UShort ''' USB-IF class code for the device Public bDeviceClass As Byte ''' USB-IF subclass code for the device Public bDeviceSubClass As Byte ''' USB-IF protocol code for the device Public bDeviceProtocol As Byte ''' Maximum packet size for control endpoint 0 Public bMaxPacketSize0 As Byte ''' USB-IF vendor ID Public idVendor As UShort ''' USB-IF product ID Public idProduct As UShort ''' Device release number in binary-coded decimal Public bcdDevice As UShort ''' Index of string descriptor describing manufacturer Public iManufacturer As Byte ''' Index of string descriptor describing product Public iProduct As Byte ''' Index of string descriptor containing device serial number Public iSerialNumber As Byte ''' Number of possible configurations Public bNumConfigurations As Byte Public Overrides Function ToString() As String Return String.Format("bLength: {0}" & Microsoft.VisualBasic.Constants.vbLf & "bDescriptorType: {1}" & Microsoft.VisualBasic.Constants.vbLf & "bcdUSB: {2}" & Microsoft.VisualBasic.Constants.vbLf & "bDeviceClass: {3}" & Microsoft.VisualBasic.Constants.vbLf & "bDeviceSubClass: {4}" & Microsoft.VisualBasic.Constants.vbLf & "bDeviceProtocol: {5}" & Microsoft.VisualBasic.Constants.vbLf & "bMaxPacketSize0: {6}" & Microsoft.VisualBasic.Constants.vbLf & "idVendor: {7}" & Microsoft.VisualBasic.Constants.vbLf & "idProduct: {8}" & Microsoft.VisualBasic.Constants.vbLf & "bcdDevice: {9}" & Microsoft.VisualBasic.Constants.vbLf & "iManufacturer: {10}" & Microsoft.VisualBasic.Constants.vbLf & "iProduct: {11}" & Microsoft.VisualBasic.Constants.vbLf & "iSerialNumber: {12}" & Microsoft.VisualBasic.Constants.vbLf & "bNumConfigurations: {13}" & Microsoft.VisualBasic.Constants.vbLf, bLength, bDescriptorType.ToString("X2") & "h", bcdUSB.ToString("X4") & "h", bDeviceClass.ToString("X2") & "h", bDeviceSubClass.ToString("X2") & "h", bDeviceProtocol.ToString("X2") & "h", bMaxPacketSize0, idVendor.ToString("X4") & "h", idProduct.ToString("X4") & "h", bcdDevice.ToString("X4") & "h", iManufacturer, iProduct, iSerialNumber, bNumConfigurations) End Function End Structure ''' A structure representing the standard USB endpoint descriptor. Public Structure USB_ENDPOINT_DESCRIPTOR ''' Size of this descriptor (in bytes) Public bLength As Byte ''' Descriptor type Public bDescriptorType As Byte ''' The address of the endpoint described by this descriptor. Public bEndpointAddress As Byte ''' Attributes which apply to the endpoint when it is configured using the bConfigurationValue. Public bmAttributes As Byte ''' Maximum packet size this endpoint is capable of sending/receiving. Public wMaxPacketSize As UShort ''' Interval for polling endpoint for data transfers. Public bInterval As Byte Public Overrides Function ToString() As String Return String.Format("bLength: {0}" & Microsoft.VisualBasic.Constants.vbLf & "bDescriptorType: {1}" & Microsoft.VisualBasic.Constants.vbLf & "bEndpointAddress: {2}" & Microsoft.VisualBasic.Constants.vbLf & "bmAttributes: {3}" & Microsoft.VisualBasic.Constants.vbLf & "wMaxPacketSize: {4}" & Microsoft.VisualBasic.Constants.vbLf & "bInterval: {5}" & Microsoft.VisualBasic.Constants.vbLf, bLength, bDescriptorType.ToString("X2") & "h", bEndpointAddress.ToString("X2") & "h", bmAttributes.ToString("X2") & "h", wMaxPacketSize, bInterval) End Function End Structure ''' A structure representing the standard USB configuration descriptor. Public Structure USB_CONFIGURATION_DESCRIPTOR ''' Size of this descriptor (in bytes) Public bLength As Byte ''' Descriptor type Public bDescriptorType As Byte ''' Total length of data returned for this configuration Public wTotalLength As UShort ''' Number of interfaces supported by this configuration Public bNumInterfaces As Byte ''' Identifier value for this configuration Public bConfigurationValue As Byte ''' Index of string descriptor describing this configuration Public iConfiguration As Byte ''' Configuration characteristics Public bmAttributes As Byte ''' ''' Maximum power consumption of the USB device from this bus in this configuration when the device is fully ''' operation. ''' Public MaxPower As Byte Public Overrides Function ToString() As String Return String.Format("bLength: {0}" & Microsoft.VisualBasic.Constants.vbLf & "bDescriptorType: {1}" & Microsoft.VisualBasic.Constants.vbLf & "wTotalLength: {2}" & Microsoft.VisualBasic.Constants.vbLf & "bNumInterfaces: {3}" & Microsoft.VisualBasic.Constants.vbLf & "bConfigurationValue: {4}" & Microsoft.VisualBasic.Constants.vbLf & "iConfiguration: {5}" & Microsoft.VisualBasic.Constants.vbLf & "bmAttributes: {6}" & Microsoft.VisualBasic.Constants.vbLf & "MaxPower: {7}" & Microsoft.VisualBasic.Constants.vbLf, bLength, bDescriptorType.ToString("X2") & "h", wTotalLength, bNumInterfaces, bConfigurationValue, iConfiguration, bmAttributes.ToString("X2") & "h", MaxPower) End Function End Structure ''' A structure representing the standard USB interface descriptor. Public Structure USB_INTERFACE_DESCRIPTOR ''' Size of this descriptor (in bytes) Public bLength As Byte ''' Descriptor type Public bDescriptorType As Byte ''' Number of this interface Public bInterfaceNumber As Byte ''' Value used to select this alternate setting for this interface Public bAlternateSetting As Byte ''' Number of endpoints used by this interface (excluding the control endpoint) Public bNumEndpoints As Byte ''' USB-IF class code for this interface Public bInterfaceClass As Byte ''' USB-IF subclass code for this interface Public bInterfaceSubClass As Byte ''' USB-IF protocol code for this interface Public bInterfaceProtocol As Byte ''' Index of string descriptor describing this interface Public iInterface As Byte Public Overrides Function ToString() As String Return String.Format("bLength: {0}" & Microsoft.VisualBasic.Constants.vbLf & "bDescriptorType: {1}" & Microsoft.VisualBasic.Constants.vbLf & "bInterfaceNumber: {2}" & Microsoft.VisualBasic.Constants.vbLf & "bAlternateSetting: {3}" & Microsoft.VisualBasic.Constants.vbLf & "bNumEndpoints: {4}" & Microsoft.VisualBasic.Constants.vbLf & "bInterfaceClass: {5}" & Microsoft.VisualBasic.Constants.vbLf & "bInterfaceSubClass: {6}" & Microsoft.VisualBasic.Constants.vbLf & "bInterfaceProtocol: {7}" & Microsoft.VisualBasic.Constants.vbLf & "iInterface: {8}" & Microsoft.VisualBasic.Constants.vbLf, bLength, bDescriptorType.ToString("X2") & "h", bInterfaceNumber, bAlternateSetting, bNumEndpoints, bInterfaceClass.ToString("X2") & "h", bInterfaceSubClass.ToString("X2") & "h", bInterfaceProtocol.ToString("X2") & "h", iInterface) End Function End Structure ''' A structure representing the standard USB string descriptor. Public Structure USB_STRING_DESCRIPTOR ''' Size of this descriptor (in bytes) Public bLength As Byte ''' Descriptor type Public bDescriptorType As Byte ''' Content of the string Public bString As String Public Overrides Function ToString() As String Return String.Format("bLength: {0}" & Microsoft.VisualBasic.Constants.vbLf & "bDescriptorType: {1}" & Microsoft.VisualBasic.Constants.vbLf & "bString: {2}" & Microsoft.VisualBasic.Constants.vbLf, bLength, bDescriptorType.ToString("X2") & "h", bString) End Function End Structure ''' A structure representing the common USB descriptor. Public Structure USB_COMMON_DESCRIPTOR ''' Size of this descriptor (in bytes) Public bLength As Byte ''' Descriptor type Public bDescriptorType As Byte Public Overrides Function ToString() As String Return String.Format("bLength: {0}" & Microsoft.VisualBasic.Constants.vbLf & "bDescriptorType: {1}" & Microsoft.VisualBasic.Constants.vbLf, bLength, bDescriptorType.ToString("X2") & "h") End Function End Structure ''' Allows hardware manufacturers to define groupings of interfaces. Public Structure USB_INTERFACE_ASSOCIATION_DESCRIPTOR ''' Size of this descriptor (in bytes) Public bLength As Byte ''' Descriptor type Public bDescriptorType As Byte ''' First interface number of the set of interfaces that follow this descriptor Public bFirstInterface As Byte ''' The Number of interfaces follow this descriptor that are considered "associated" Public bInterfaceCount As Byte ''' \c bInterfaceClass used for this associated interfaces Public bFunctionClass As Byte ''' \c bInterfaceSubClass used for the associated interfaces Public bFunctionSubClass As Byte ''' \c bInterfaceProtocol used for the associated interfaces Public bFunctionProtocol As Byte ''' Index of string descriptor describing the associated interfaces Public iFunction As Byte Public Overrides Function ToString() As String Return String.Format("bLength: {0}" & Microsoft.VisualBasic.Constants.vbLf & "bDescriptorType: {1}" & Microsoft.VisualBasic.Constants.vbLf & "bFirstInterface: {2}" & Microsoft.VisualBasic.Constants.vbLf & "bInterfaceCount: {3}" & Microsoft.VisualBasic.Constants.vbLf & "bFunctionClass: {4}" & Microsoft.VisualBasic.Constants.vbLf & "bFunctionSubClass: {5}" & Microsoft.VisualBasic.Constants.vbLf & "bFunctionProtocol: {6}" & Microsoft.VisualBasic.Constants.vbLf & "iFunction: {7}" & Microsoft.VisualBasic.Constants.vbLf, bLength, bDescriptorType.ToString("X2") & "h", bFirstInterface, bInterfaceCount, bFunctionClass.ToString("X2") & "h", bFunctionSubClass.ToString("X2") & "h", bFunctionProtocol.ToString("X2") & "h", iFunction) End Function End Structure ''' USB core driver API information structure. Public Structure KUSB_DRIVER_API_INFO ''' \readonly Driver id of the driver api. Public DriverID As Integer ''' \readonly Number of valid functions contained in the driver API. Public FunctionCount As Integer Public Overrides Function ToString() As String Return String.Format("DriverID: {0}" & Microsoft.VisualBasic.Constants.vbLf & "FunctionCount: {1}" & Microsoft.VisualBasic.Constants.vbLf, DriverID, FunctionCount) End Function End Structure ''' Driver API function set structure. Public Structure KUSB_DRIVER_API ''' Driver API information. Public Info As KUSB_DRIVER_API_INFO Public Init As KUSB_InitDelegate Public Free As KUSB_FreeDelegate Public ClaimInterface As KUSB_ClaimInterfaceDelegate Public ReleaseInterface As KUSB_ReleaseInterfaceDelegate Public SetAltInterface As KUSB_SetAltInterfaceDelegate Public GetAltInterface As KUSB_GetAltInterfaceDelegate Public GetDescriptor As KUSB_GetDescriptorDelegate Public ControlTransfer As KUSB_ControlTransferDelegate Public SetPowerPolicy As KUSB_SetPowerPolicyDelegate Public GetPowerPolicy As KUSB_GetPowerPolicyDelegate Public SetConfiguration As KUSB_SetConfigurationDelegate Public GetConfiguration As KUSB_GetConfigurationDelegate Public ResetDevice As KUSB_ResetDeviceDelegate Public Initialize As KUSB_InitializeDelegate Public SelectInterface As KUSB_SelectInterfaceDelegate Public GetAssociatedInterface As KUSB_GetAssociatedInterfaceDelegate Public Clone As KUSB_CloneDelegate Public QueryInterfaceSettings As KUSB_QueryInterfaceSettingsDelegate Public QueryDeviceInformation As KUSB_QueryDeviceInformationDelegate Public SetCurrentAlternateSetting As KUSB_SetCurrentAlternateSettingDelegate Public GetCurrentAlternateSetting As KUSB_GetCurrentAlternateSettingDelegate Public QueryPipe As KUSB_QueryPipeDelegate Public SetPipePolicy As KUSB_SetPipePolicyDelegate Public GetPipePolicy As KUSB_GetPipePolicyDelegate Public ReadPipe As KUSB_ReadPipeDelegate Public WritePipe As KUSB_WritePipeDelegate Public ResetPipe As KUSB_ResetPipeDelegate Public AbortPipe As KUSB_AbortPipeDelegate Public FlushPipe As KUSB_FlushPipeDelegate Public IsoReadPipe As KUSB_IsoReadPipeDelegate Public IsoWritePipe As KUSB_IsoWritePipeDelegate Public GetCurrentFrameNumber As KUSB_GetCurrentFrameNumberDelegate Public GetOverlappedResult As KUSB_GetOverlappedResultDelegate Public GetProperty As KUSB_GetPropertyDelegate Public IsochReadPipe As KUSB_IsochReadPipeDelegate Public IsochWritePipe As KUSB_IsochWritePipeDelegate Public QueryPipeEx As KUSB_QueryPipeExDelegate Public GetSuperSpeedPipeCompanionDescriptor As KUSB_GetSuperSpeedPipeCompanionDescriptorDelegate End Structure ''' Hot plug parameter structure. Public Structure KHOT_PARAMS ''' Hot plug event window handle to send/post messages when notifications occur. Public UserHwnd As IntPtr ''' WM_USER message start offset used when sending/posting messages, See details. Public UserMessage As UInteger ''' Additional init/config parameters Public Flags As KHOT_FLAG ''' File pattern matches for restricting notifcations to a single/group or all supported usb devices. Public PatternMatch As KLST_PATTERN_MATCH ''' Hot plug event callback function invoked when notifications occur. Public OnHotPlug As KHOT_PLUG_CB ''' \b WM_POWERBROADCAST event callback function invoked when a power-management event has occurred. Public OnPowerBroadcast As KHOT_POWER_BROADCAST_CB Public Overrides Function ToString() As String Return String.Format("UserHwnd: {0}" & Microsoft.VisualBasic.Constants.vbLf & "UserMessage: {1}" & Microsoft.VisualBasic.Constants.vbLf & "Flags: {2}" & Microsoft.VisualBasic.Constants.vbLf, UserHwnd.ToString("X16") & "h", UserMessage.ToString("X8") & "h", Flags.ToString()) End Function End Structure Public Structure KSTM_XFER_CONTEXT Private ReadOnly mHandlePtr As IntPtr Public Sub New(ByVal Handle As IntPtr) mHandlePtr = Handle End Sub Public ReadOnly Property Pointer As IntPtr Get Return mHandlePtr End Get End Property ''' KSTM_XFER_CONTEXT_MAP is used for calculating field offsets only Private Structure KSTM_XFER_CONTEXT_MAP ''' Internal stream buffer. Private ReadOnly Buffer As IntPtr ''' Size of internal stream buffer. Private ReadOnly BufferSize As Integer ''' Number of bytes to write or number of bytes read. Private ReadOnly TransferLength As Integer ''' User defined state. Private ReadOnly UserState As IntPtr End Structure Private Shared ReadOnly ofsBuffer As Integer = Marshal.OffsetOf(GetType(KSTM_XFER_CONTEXT_MAP), "Buffer").ToInt32() Private Shared ReadOnly ofsBufferSize As Integer = Marshal.OffsetOf(GetType(KSTM_XFER_CONTEXT_MAP), "BufferSize").ToInt32() Private Shared ReadOnly ofsTransferLength As Integer = Marshal.OffsetOf(GetType(KSTM_XFER_CONTEXT_MAP), "TransferLength").ToInt32() Private Shared ReadOnly ofsUserState As Integer = Marshal.OffsetOf(GetType(KSTM_XFER_CONTEXT_MAP), "UserState").ToInt32() ''' Internal stream buffer. Public ReadOnly Property Buffer As IntPtr Get Return Marshal.ReadIntPtr(mHandlePtr, ofsBuffer) End Get End Property ''' Size of internal stream buffer. Public ReadOnly Property BufferSize As Integer Get Return Marshal.ReadInt32(mHandlePtr, ofsBufferSize) End Get End Property ''' Number of bytes to write or number of bytes read. Public ReadOnly Property TransferLength As Integer Get Return Marshal.ReadInt32(mHandlePtr, ofsTransferLength) End Get End Property ''' User defined state. Public Property UserState As IntPtr Get Return Marshal.ReadIntPtr(mHandlePtr, ofsUserState) End Get Set(ByVal value As IntPtr) Marshal.WriteIntPtr(mHandlePtr, ofsUserState, value) End Set End Property Public Overrides Function ToString() As String Return String.Format("Buffer: {0}" & Microsoft.VisualBasic.Constants.vbLf & "BufferSize: {1}" & Microsoft.VisualBasic.Constants.vbLf & "TransferLength: {2}" & Microsoft.VisualBasic.Constants.vbLf & "UserState: {3}" & Microsoft.VisualBasic.Constants.vbLf, Buffer.ToString("X16") & "h", BufferSize, TransferLength, UserState.ToString("X16") & "h") End Function End Structure Public Structure KSTM_INFO Private ReadOnly mHandlePtr As IntPtr Public Sub New(ByVal Handle As IntPtr) mHandlePtr = Handle End Sub Public ReadOnly Property Pointer As IntPtr Get Return mHandlePtr End Get End Property ''' KSTM_INFO_MAP is used for calculating field offsets only Private Structure KSTM_INFO_MAP ''' \ref KUSB_HANDLE this stream uses. Private ReadOnly UsbHandle As IntPtr ''' This parameter corresponds to the bEndpointAddress field in the endpoint descriptor. Private ReadOnly PipeID As Byte ''' Maximum transfer read/write request allowed pending. Private ReadOnly MaxPendingTransfers As Integer ''' Maximum transfer sage size. Private ReadOnly MaxTransferSize As Integer ''' Maximum number of I/O request allowed pending. Private ReadOnly MaxPendingIO As Integer ''' Populated with the endpoint descriptor for the specified \c PipeID. Private ReadOnly EndpointDescriptor As USB_ENDPOINT_DESCRIPTOR ''' Populated with the driver api for the specified \c UsbHandle. Private ReadOnly DriverAPI As KUSB_DRIVER_API ''' Populated with the device file handle for the specified \c UsbHandle. Private ReadOnly DeviceHandle As IntPtr ''' Stream handle. Private ReadOnly StreamHandle As IntPtr ''' Stream info user defined state. Private ReadOnly UserState As IntPtr End Structure Private Shared ReadOnly ofsUsbHandle As Integer = Marshal.OffsetOf(GetType(KSTM_INFO_MAP), "UsbHandle").ToInt32() Private Shared ReadOnly ofsPipeID As Integer = Marshal.OffsetOf(GetType(KSTM_INFO_MAP), "PipeID").ToInt32() Private Shared ReadOnly ofsMaxPendingTransfers As Integer = Marshal.OffsetOf(GetType(KSTM_INFO_MAP), "MaxPendingTransfers").ToInt32() Private Shared ReadOnly ofsMaxTransferSize As Integer = Marshal.OffsetOf(GetType(KSTM_INFO_MAP), "MaxTransferSize").ToInt32() Private Shared ReadOnly ofsMaxPendingIO As Integer = Marshal.OffsetOf(GetType(KSTM_INFO_MAP), "MaxPendingIO").ToInt32() Private Shared ReadOnly ofsEndpointDescriptor As Integer = Marshal.OffsetOf(GetType(KSTM_INFO_MAP), "EndpointDescriptor").ToInt32() Private Shared ReadOnly ofsDriverAPI As Integer = Marshal.OffsetOf(GetType(KSTM_INFO_MAP), "DriverAPI").ToInt32() Private Shared ReadOnly ofsDeviceHandle As Integer = Marshal.OffsetOf(GetType(KSTM_INFO_MAP), "DeviceHandle").ToInt32() Private Shared ReadOnly ofsStreamHandle As Integer = Marshal.OffsetOf(GetType(KSTM_INFO_MAP), "StreamHandle").ToInt32() Private Shared ReadOnly ofsUserState As Integer = Marshal.OffsetOf(GetType(KSTM_INFO_MAP), "UserState").ToInt32() ''' \ref KUSB_HANDLE this stream uses. Public ReadOnly Property UsbHandle As IntPtr Get Return Marshal.ReadIntPtr(mHandlePtr, ofsUsbHandle) End Get End Property ''' This parameter corresponds to the bEndpointAddress field in the endpoint descriptor. Public ReadOnly Property PipeID As Byte Get Return Marshal.ReadByte(mHandlePtr, ofsPipeID) End Get End Property ''' Maximum transfer read/write request allowed pending. Public ReadOnly Property MaxPendingTransfers As Integer Get Return Marshal.ReadInt32(mHandlePtr, ofsMaxPendingTransfers) End Get End Property ''' Maximum transfer sage size. Public ReadOnly Property MaxTransferSize As Integer Get Return Marshal.ReadInt32(mHandlePtr, ofsMaxTransferSize) End Get End Property ''' Maximum number of I/O request allowed pending. Public ReadOnly Property MaxPendingIO As Integer Get Return Marshal.ReadInt32(mHandlePtr, ofsMaxPendingIO) End Get End Property ''' Populated with the endpoint descriptor for the specified \c PipeID. Public ReadOnly Property EndpointDescriptor As USB_ENDPOINT_DESCRIPTOR Get Return CType(Marshal.PtrToStructure(New IntPtr(mHandlePtr.ToInt64() + ofsEndpointDescriptor), GetType(USB_ENDPOINT_DESCRIPTOR)), USB_ENDPOINT_DESCRIPTOR) End Get End Property ''' Populated with the driver api for the specified \c UsbHandle. Public ReadOnly Property DriverAPI As KUSB_DRIVER_API Get Return CType(Marshal.PtrToStructure(New IntPtr(mHandlePtr.ToInt64() + ofsDriverAPI), GetType(KUSB_DRIVER_API)), KUSB_DRIVER_API) End Get End Property ''' Populated with the device file handle for the specified \c UsbHandle. Public ReadOnly Property DeviceHandle As IntPtr Get Return Marshal.ReadIntPtr(mHandlePtr, ofsDeviceHandle) End Get End Property ''' Stream handle. Public ReadOnly Property StreamHandle As IntPtr Get Return Marshal.ReadIntPtr(mHandlePtr, ofsStreamHandle) End Get End Property ''' Stream info user defined state. Public Property UserState As IntPtr Get Return Marshal.ReadIntPtr(mHandlePtr, ofsUserState) End Get Set(ByVal value As IntPtr) Marshal.WriteIntPtr(mHandlePtr, ofsUserState, value) End Set End Property Public Overrides Function ToString() As String Return String.Format("UsbHandle: {0}" & Microsoft.VisualBasic.Constants.vbLf & "PipeID: {1}" & Microsoft.VisualBasic.Constants.vbLf & "MaxPendingTransfers: {2}" & Microsoft.VisualBasic.Constants.vbLf & "MaxTransferSize: {3}" & Microsoft.VisualBasic.Constants.vbLf & "MaxPendingIO: {4}" & Microsoft.VisualBasic.Constants.vbLf & "DeviceHandle: {5}" & Microsoft.VisualBasic.Constants.vbLf & "StreamHandle: {6}" & Microsoft.VisualBasic.Constants.vbLf & "UserState: {7}" & Microsoft.VisualBasic.Constants.vbLf, UsbHandle.ToString("X16") & "h", PipeID.ToString("X2") & "h", MaxPendingTransfers, MaxTransferSize, MaxPendingIO, DeviceHandle.ToString("X16") & "h", StreamHandle.ToString("X16") & "h", UserState.ToString("X16") & "h") End Function End Structure ''' Stream callback structure. Public Structure KSTM_CALLBACK ''' Executed when a transfer error occurs. Public [Error] As KSTM_ERROR_CB ''' Executed to submit a transfer. Public Submit As KSTM_SUBMIT_CB ''' Executed when a valid transfer completes. Public Complete As KSTM_COMPLETE_CB ''' Executed for every transfer context when the stream is started with \ref StmK_Start. Public Started As KSTM_STARTED_CB ''' Executed for every transfer context when the stream is stopped with \ref StmK_Stop. Public Stopped As KSTM_STOPPED_CB ''' Executed immediately after a transfer completes. Public BeforeComplete As KSTM_BEFORE_COMPLETE_CB End Structure #End Region #Region "Delegates" Public Delegate Function KLIB_HANDLE_CLEANUP_CB( <[In]> ByVal Handle As IntPtr, ByVal HandleType As KLIB_HANDLE_TYPE, ByVal UserContext As IntPtr) As Integer Public Delegate Function KISO_ENUM_PACKETS_CB(ByVal PacketIndex As UInteger, <[In]> ByRef IsoPacket As KISO_PACKET, ByVal UserState As IntPtr) As Boolean Public Delegate Function KISOCH_ENUM_PACKETS_CB(ByVal PacketIndex As UInteger, ByRef Offset As UInteger, ByRef Length As UInteger, ByRef Status As UInteger, ByVal UserState As IntPtr) As Boolean Public Delegate Function KLST_ENUM_DEVINFO_CB( <[In]> ByVal DeviceList As KLST_HANDLE, <[In]> ByVal DeviceInfo As KLST_DEVINFO_HANDLE, ByVal Context As IntPtr) As Boolean Public Delegate Function KUSB_InitDelegate( ByRef InterfaceHandle As KUSB_HANDLE, <[In]> ByVal DevInfo As KLST_DEVINFO_HANDLE) As Boolean Public Delegate Function KUSB_FreeDelegate( <[In]> ByVal InterfaceHandle As KUSB_HANDLE) As Boolean Public Delegate Function KUSB_ClaimInterfaceDelegate( <[In]> ByVal InterfaceHandle As KUSB_HANDLE, ByVal NumberOrIndex As Byte, ByVal IsIndex As Boolean) As Boolean Public Delegate Function KUSB_ReleaseInterfaceDelegate( <[In]> ByVal InterfaceHandle As KUSB_HANDLE, ByVal NumberOrIndex As Byte, ByVal IsIndex As Boolean) As Boolean Public Delegate Function KUSB_SetAltInterfaceDelegate( <[In]> ByVal InterfaceHandle As KUSB_HANDLE, ByVal NumberOrIndex As Byte, ByVal IsIndex As Boolean, ByVal AltSettingNumber As Byte) As Boolean Public Delegate Function KUSB_GetAltInterfaceDelegate( <[In]> ByVal InterfaceHandle As KUSB_HANDLE, ByVal NumberOrIndex As Byte, ByVal IsIndex As Boolean, ByRef AltSettingNumber As Byte) As Boolean Public Delegate Function KUSB_GetDescriptorDelegate( <[In]> ByVal InterfaceHandle As KUSB_HANDLE, ByVal DescriptorType As Byte, ByVal Index As Byte, ByVal LanguageID As UShort, ByVal Buffer As IntPtr, ByVal BufferLength As UInteger, ByRef LengthTransferred As UInteger) As Boolean Public Delegate Function KUSB_ControlTransferDelegate( <[In]> ByVal InterfaceHandle As KUSB_HANDLE, ByVal SetupPacket As WINUSB_SETUP_PACKET, ByVal Buffer As IntPtr, ByVal BufferLength As UInteger, ByRef LengthTransferred As UInteger, ByVal Overlapped As IntPtr) As Boolean Public Delegate Function KUSB_SetPowerPolicyDelegate( <[In]> ByVal InterfaceHandle As KUSB_HANDLE, ByVal PolicyType As UInteger, ByVal ValueLength As UInteger, ByVal Value As IntPtr) As Boolean Public Delegate Function KUSB_GetPowerPolicyDelegate( <[In]> ByVal InterfaceHandle As KUSB_HANDLE, ByVal PolicyType As UInteger, ByRef ValueLength As UInteger, ByVal Value As IntPtr) As Boolean Public Delegate Function KUSB_SetConfigurationDelegate( <[In]> ByVal InterfaceHandle As KUSB_HANDLE, ByVal ConfigurationNumber As Byte) As Boolean Public Delegate Function KUSB_GetConfigurationDelegate( <[In]> ByVal InterfaceHandle As KUSB_HANDLE, ByRef ConfigurationNumber As Byte) As Boolean Public Delegate Function KUSB_ResetDeviceDelegate( <[In]> ByVal InterfaceHandle As KUSB_HANDLE) As Boolean Public Delegate Function KUSB_InitializeDelegate(ByVal DeviceHandle As IntPtr, ByRef InterfaceHandle As KUSB_HANDLE) As Boolean Public Delegate Function KUSB_SelectInterfaceDelegate( <[In]> ByVal InterfaceHandle As KUSB_HANDLE, ByVal NumberOrIndex As Byte, ByVal IsIndex As Boolean) As Boolean Public Delegate Function KUSB_GetAssociatedInterfaceDelegate( <[In]> ByVal InterfaceHandle As KUSB_HANDLE, ByVal AssociatedInterfaceIndex As Byte, ByRef AssociatedInterfaceHandle As KUSB_HANDLE) As Boolean Public Delegate Function KUSB_CloneDelegate( <[In]> ByVal InterfaceHandle As KUSB_HANDLE, ByRef DstInterfaceHandle As KUSB_HANDLE) As Boolean Public Delegate Function KUSB_QueryInterfaceSettingsDelegate( <[In]> ByVal InterfaceHandle As KUSB_HANDLE, ByVal AltSettingIndex As Byte, ByRef UsbAltInterfaceDescriptor As USB_INTERFACE_DESCRIPTOR) As Boolean Public Delegate Function KUSB_QueryDeviceInformationDelegate( <[In]> ByVal InterfaceHandle As KUSB_HANDLE, ByVal InformationType As UInteger, ByRef BufferLength As UInteger, ByVal Buffer As IntPtr) As Boolean Public Delegate Function KUSB_SetCurrentAlternateSettingDelegate( <[In]> ByVal InterfaceHandle As KUSB_HANDLE, ByVal AltSettingNumber As Byte) As Boolean Public Delegate Function KUSB_GetCurrentAlternateSettingDelegate( <[In]> ByVal InterfaceHandle As KUSB_HANDLE, ByRef AltSettingNumber As Byte) As Boolean Public Delegate Function KUSB_QueryPipeDelegate( <[In]> ByVal InterfaceHandle As KUSB_HANDLE, ByVal AltSettingNumber As Byte, ByVal PipeIndex As Byte, ByRef PipeInformation As WINUSB_PIPE_INFORMATION) As Boolean Public Delegate Function KUSB_QueryPipeExDelegate( <[In]> ByVal InterfaceHandle As KUSB_HANDLE, ByVal AlternateSettingNumber As Byte, ByVal PipeIndex As Byte, ByRef PipeInformationEx As WINUSB_PIPE_INFORMATION_EX) As Boolean Public Delegate Function KUSB_GetSuperSpeedPipeCompanionDescriptorDelegate( <[In]> ByVal Handle As KUSB_HANDLE, ByVal AltSettingNumber As Byte, ByVal PipeIndex As Byte, ByRef PipeCompanionDescriptor As USB_SUPERSPEED_ENDPOINT_COMPANION_DESCRIPTOR) As Boolean Public Delegate Function KUSB_SetPipePolicyDelegate( <[In]> ByVal InterfaceHandle As KUSB_HANDLE, ByVal PipeID As Byte, ByVal PolicyType As UInteger, ByVal ValueLength As UInteger, ByVal Value As IntPtr) As Boolean Public Delegate Function KUSB_GetPipePolicyDelegate( <[In]> ByVal InterfaceHandle As KUSB_HANDLE, ByVal PipeID As Byte, ByVal PolicyType As UInteger, ByRef ValueLength As UInteger, ByVal Value As IntPtr) As Boolean Public Delegate Function KUSB_ReadPipeDelegate( <[In]> ByVal InterfaceHandle As KUSB_HANDLE, ByVal PipeID As Byte, ByVal Buffer As IntPtr, ByVal BufferLength As UInteger, ByRef LengthTransferred As UInteger, ByVal Overlapped As IntPtr) As Boolean Public Delegate Function KUSB_WritePipeDelegate( <[In]> ByVal InterfaceHandle As KUSB_HANDLE, ByVal PipeID As Byte, ByVal Buffer As IntPtr, ByVal BufferLength As UInteger, ByRef LengthTransferred As UInteger, ByVal Overlapped As IntPtr) As Boolean Public Delegate Function KUSB_ResetPipeDelegate( <[In]> ByVal InterfaceHandle As KUSB_HANDLE, ByVal PipeID As Byte) As Boolean Public Delegate Function KUSB_AbortPipeDelegate( <[In]> ByVal InterfaceHandle As KUSB_HANDLE, ByVal PipeID As Byte) As Boolean Public Delegate Function KUSB_FlushPipeDelegate( <[In]> ByVal InterfaceHandle As KUSB_HANDLE, ByVal PipeID As Byte) As Boolean Public Delegate Function KUSB_IsoReadPipeDelegate( <[In]> ByVal InterfaceHandle As KUSB_HANDLE, ByVal PipeID As Byte, ByVal Buffer As IntPtr, ByVal BufferLength As UInteger, ByVal Overlapped As IntPtr, <[In]> ByVal IsoContext As KISO_CONTEXT) As Boolean Public Delegate Function KUSB_IsoWritePipeDelegate( <[In]> ByVal InterfaceHandle As KUSB_HANDLE, ByVal PipeID As Byte, ByVal Buffer As IntPtr, ByVal BufferLength As UInteger, ByVal Overlapped As IntPtr, <[In]> ByVal IsoContext As KISO_CONTEXT) As Boolean Public Delegate Function KUSB_GetCurrentFrameNumberDelegate( <[In]> ByVal InterfaceHandle As KUSB_HANDLE, ByRef FrameNumber As UInteger) As Boolean Public Delegate Function KUSB_GetOverlappedResultDelegate( <[In]> ByVal InterfaceHandle As KUSB_HANDLE, ByVal Overlapped As IntPtr, ByRef lpNumberOfBytesTransferred As UInteger, ByVal bWait As Boolean) As Boolean Public Delegate Function KUSB_GetPropertyDelegate( <[In]> ByVal InterfaceHandle As KUSB_HANDLE, ByVal PropertyType As KUSB_PROPERTY, ByRef PropertySize As UInteger, ByVal Value As IntPtr) As Boolean Public Delegate Function KUSB_IsochReadPipeDelegate( <[In]> ByVal IsochHandle As KISOCH_HANDLE, ByVal DataLength As UInteger, ByRef FrameNumber As UInteger, ByVal NumberOfPackets As UInteger, ByVal Overlapped As IntPtr) As Boolean Public Delegate Function KUSB_IsochWritePipeDelegate( <[In]> ByVal IsochHandle As KISOCH_HANDLE, ByVal DataLength As UInteger, ByRef FrameNumber As UInteger, ByVal NumberOfPackets As UInteger, ByVal Overlapped As IntPtr) As Boolean Public Delegate Sub KHOT_PLUG_CB( <[In]> ByVal HotHandle As KHOT_HANDLE, <[In]> ByVal DeviceInfo As KLST_DEVINFO_HANDLE, ByVal PlugType As KLST_SYNC_FLAG) Public Delegate Sub KHOT_POWER_BROADCAST_CB( <[In]> ByVal HotHandle As KHOT_HANDLE, <[In]> ByVal DeviceInfo As KLST_DEVINFO_HANDLE, ByVal PbtEvent As UInteger) Public Delegate Function KSTM_ERROR_CB( <[In]> ByVal StreamInfo As KSTM_INFO, <[In]> ByVal XferContext As KSTM_XFER_CONTEXT, ByVal XferContextIndex As Integer, ByVal ErrorCode As Integer) As Integer Public Delegate Function KSTM_SUBMIT_CB( <[In]> ByVal StreamInfo As KSTM_INFO, <[In]> ByVal XferContext As KSTM_XFER_CONTEXT, ByVal XferContextIndex As Integer, ByVal Overlapped As IntPtr) As Integer Public Delegate Function KSTM_STARTED_CB( <[In]> ByVal StreamInfo As KSTM_INFO, <[In]> ByVal XferContext As KSTM_XFER_CONTEXT, ByVal XferContextIndex As Integer) As Integer Public Delegate Function KSTM_STOPPED_CB( <[In]> ByVal StreamInfo As KSTM_INFO, <[In]> ByVal XferContext As KSTM_XFER_CONTEXT, ByVal XferContextIndex As Integer) As Integer Public Delegate Function KSTM_COMPLETE_CB( <[In]> ByVal StreamInfo As KSTM_INFO, <[In]> ByVal XferContext As KSTM_XFER_CONTEXT, ByVal XferContextIndex As Integer, ByVal ErrorCode As Integer) As Integer Public Delegate Function KSTM_BEFORE_COMPLETE_CB( <[In]> ByVal StreamInfo As KSTM_INFO, <[In]> ByVal XferContext As KSTM_XFER_CONTEXT, ByVal XferContextIndex As Integer, ByRef ErrorCode As Integer) As KSTM_COMPLETE_RESULT #End Region Public Class LstK Implements IDisposable Protected mbDisposed As Boolean Protected mHandleStruct As KLST_HANDLE Protected Sub New() End Sub ''' Initializes a new usb device list containing all supported devices. Public Sub New(ByVal Flags As KLST_FLAG) Dim success = LstK_Init(mHandleStruct, Flags) If Not success Then Throw New Exception(String.Format("{0} failed initializing. ErrorCode={1:X8}h", [GetType]().Name, Marshal.GetLastWin32Error())) Call Debug.Print("{0} Init: handle 0x{1:X16}", [GetType]().Name, mHandleStruct.Pointer.ToInt64()) End Sub ''' Initializes a new usb device list containing only devices matching a specific class GUID. Public Sub New(ByVal Flags As KLST_FLAG, ByRef PatternMatch As KLST_PATTERN_MATCH) Dim success = LstK_InitEx(mHandleStruct, Flags, PatternMatch) If Not success Then Throw New Exception(String.Format("{0} failed initializing. ErrorCode={1:X8}h", [GetType]().Name, Marshal.GetLastWin32Error())) Call Debug.Print("{0} Init: handle 0x{1:X16}", [GetType]().Name, mHandleStruct.Pointer.ToInt64()) End Sub ''' Gets the handle class structure. Public ReadOnly Property Handle As KLST_HANDLE Get Return mHandleStruct End Get End Property ''' Explicitly closes and frees the handle. Public Overridable Sub Dispose() Implements IDisposable.Dispose Dispose(True) GC.SuppressFinalize(Me) End Sub Protected Overrides Sub Finalize() Dispose(False) End Sub ''' Calls the dispose method. Public Overridable Sub Free() Dispose() End Sub Protected Overridable Sub Dispose(ByVal disposing As Boolean) If Not mbDisposed Then If mHandleStruct.Pointer <> IntPtr.Zero Then LstK_Free(mHandleStruct) Call Debug.Print("{0} Dispose: Freed Handle:{1:X16}h Explicit:{2}", [GetType]().Name, mHandleStruct.Pointer.ToInt64(), disposing) Else Call Debug.Print("{0} Dispose: [WARNING] Handle is null", [GetType]().Name) End If mHandleStruct = New KLST_HANDLE(IntPtr.Zero) mbDisposed = True End If End Sub ''' Initializes a new usb device list containing all supported devices. Protected Function Init(ByVal Flags As KLST_FLAG) As Boolean Dim success = LstK_Init(mHandleStruct, Flags) If Not success Then Throw New Exception(String.Format("{0} failed initializing. ErrorCode={1:X8}h", [GetType]().Name, Marshal.GetLastWin32Error())) Call Debug.Print("{0} Init: handle 0x{1:X16}", [GetType]().Name, mHandleStruct.Pointer.ToInt64()) Return True End Function ''' Initializes a new usb device list containing only devices matching a specific class GUID. Protected Function InitEx(ByVal Flags As KLST_FLAG, ByRef PatternMatch As KLST_PATTERN_MATCH) As Boolean Dim success = LstK_InitEx(mHandleStruct, Flags, PatternMatch) If Not success Then Throw New Exception(String.Format("{0} failed initializing. ErrorCode={1:X8}h", [GetType]().Name, Marshal.GetLastWin32Error())) Call Debug.Print("{0} Init: handle 0x{1:X16}", [GetType]().Name, mHandleStruct.Pointer.ToInt64()) Return True End Function ''' Enumerates \ref KLST_DEVINFO elements of a \ref KLST_HANDLE. Public Overridable Function Enumerate(ByVal EnumDevListCB As KLST_ENUM_DEVINFO_CB, ByVal Context As IntPtr) As Boolean Return LstK_Enumerate(mHandleStruct, EnumDevListCB, Context) End Function ''' Gets the \ref KLST_DEVINFO element for the current position. Public Overridable Function Current( ByRef DeviceInfo As KLST_DEVINFO_HANDLE) As Boolean Return LstK_Current(mHandleStruct, DeviceInfo) End Function ''' Advances the device list current \ref KLST_DEVINFO position. Public Overridable Function MoveNext( ByRef DeviceInfo As KLST_DEVINFO_HANDLE) As Boolean Return LstK_MoveNext(mHandleStruct, DeviceInfo) End Function ''' Sets the device list to its initial position, which is before the first element in the list. Public Overridable Sub MoveReset() LstK_MoveReset(mHandleStruct) End Sub ''' Find a device by vendor and product id Public Overridable Function FindByVidPid(ByVal Vid As Integer, ByVal Pid As Integer, ByRef DeviceInfo As KLST_DEVINFO_HANDLE) As Boolean Return LstK_FindByVidPid(mHandleStruct, Vid, Pid, DeviceInfo) End Function ''' Counts the number of device info elements in a device list. Public Overridable Function Count(ByRef pCount As UInteger) As Boolean Return LstK_Count(mHandleStruct, pCount) End Function End Class Public Class HotK Implements IDisposable Protected mbDisposed As Boolean Protected mHandleStruct As KHOT_HANDLE Protected Sub New() End Sub ''' Creates a new hot-plug handle for USB device arrival/removal event monitoring. Public Sub New(ByRef InitParams As KHOT_PARAMS) Dim success = HotK_Init(mHandleStruct, InitParams) If Not success Then Throw New Exception(String.Format("{0} failed initializing. ErrorCode={1:X8}h", [GetType]().Name, Marshal.GetLastWin32Error())) Call Debug.Print("{0} Init: handle 0x{1:X16}", [GetType]().Name, mHandleStruct.Pointer.ToInt64()) End Sub ''' Gets the handle class structure. Public ReadOnly Property Handle As KHOT_HANDLE Get Return mHandleStruct End Get End Property ''' Explicitly closes and frees the handle. Public Overridable Sub Dispose() Implements IDisposable.Dispose Dispose(True) GC.SuppressFinalize(Me) End Sub Protected Overrides Sub Finalize() Dispose(False) End Sub ''' Calls the dispose method. Public Overridable Sub Free() Dispose() End Sub Protected Overridable Sub Dispose(ByVal disposing As Boolean) If Not mbDisposed Then If mHandleStruct.Pointer <> IntPtr.Zero Then HotK_Free(mHandleStruct) Call Debug.Print("{0} Dispose: Freed Handle:{1:X16}h Explicit:{2}", [GetType]().Name, mHandleStruct.Pointer.ToInt64(), disposing) Else Call Debug.Print("{0} Dispose: [WARNING] Handle is null", [GetType]().Name) End If mHandleStruct = New KHOT_HANDLE(IntPtr.Zero) mbDisposed = True End If End Sub ''' Creates a new hot-plug handle for USB device arrival/removal event monitoring. Protected Function Init(ByRef InitParams As KHOT_PARAMS) As Boolean Dim success = HotK_Init(mHandleStruct, InitParams) If Not success Then Throw New Exception(String.Format("{0} failed initializing. ErrorCode={1:X8}h", [GetType]().Name, Marshal.GetLastWin32Error())) Call Debug.Print("{0} Init: handle 0x{1:X16}", [GetType]().Name, mHandleStruct.Pointer.ToInt64()) Return True End Function ''' Frees all hot-plug handles initialized with \ref HotK_Init. Public Shared Sub FreeAll() HotK_FreeAll() End Sub End Class Public Class UsbK Implements IDisposable Protected driverAPI As KUSB_DRIVER_API Protected mbDisposed As Boolean Protected mHandleStruct As KUSB_HANDLE Protected Sub New() End Sub ''' Creates/opens a libusbK interface handle from the device list. This is a preferred method. Public Sub New(ByVal DevInfo As KLST_DEVINFO_HANDLE) Dim success = LibK_LoadDriverAPI(driverAPI, DevInfo.DriverID) If Not success Then Throw New Exception(String.Format("{0} failed loading Driver API. ErrorCode={1:X8}h", [GetType]().Name, Marshal.GetLastWin32Error())) success = driverAPI.Init(mHandleStruct, DevInfo) If Not success Then Throw New Exception(String.Format("{0} failed initializing usb device. ErrorCode={1:X8}h", [GetType]().Name, Marshal.GetLastWin32Error())) Call Debug.Print("{0} Init: handle 0x{1:X16}", [GetType]().Name, mHandleStruct.Pointer.ToInt64()) End Sub ''' Creates a libusbK handle for the device specified by a file handle. Public Sub New(ByVal DeviceHandle As IntPtr, ByVal driverID As KUSB_DRVID) Dim success = LibK_LoadDriverAPI(driverAPI, driverID) If Not success Then Throw New Exception(String.Format("{0} failed loading Driver API. ErrorCode={1:X8}h", [GetType]().Name, Marshal.GetLastWin32Error())) success = driverAPI.Initialize(DeviceHandle, mHandleStruct) If Not success Then Throw New Exception(String.Format("{0} failed initializing usb device. ErrorCode={1:X8}h", [GetType]().Name, Marshal.GetLastWin32Error())) Call Debug.Print("{0} Init: handle 0x{1:X16}", [GetType]().Name, mHandleStruct.Pointer.ToInt64()) End Sub ''' Gets the handle class structure. Public ReadOnly Property Handle As KUSB_HANDLE Get Return mHandleStruct End Get End Property ''' Explicitly closes and frees the handle. Public Overridable Sub Dispose() Implements IDisposable.Dispose Dispose(True) GC.SuppressFinalize(Me) End Sub Protected Overrides Sub Finalize() Dispose(False) End Sub ''' Calls the dispose method. Public Overridable Sub Free() Dispose() End Sub Protected Overridable Sub Dispose(ByVal disposing As Boolean) If Not mbDisposed Then If mHandleStruct.Pointer <> IntPtr.Zero Then UsbK_Free(mHandleStruct) Call Debug.Print("{0} Dispose: Freed Handle:{1:X16}h Explicit:{2}", [GetType]().Name, mHandleStruct.Pointer.ToInt64(), disposing) Else Call Debug.Print("{0} Dispose: [WARNING] Handle is null", [GetType]().Name) End If mHandleStruct = New KUSB_HANDLE(IntPtr.Zero) mbDisposed = True End If End Sub ''' Creates/opens a libusbK interface handle from the device list. This is a preferred method. Protected Function Init(ByVal DevInfo As KLST_DEVINFO_HANDLE) As Boolean Dim success = LibK_LoadDriverAPI(driverAPI, DevInfo.DriverID) If Not success Then Throw New Exception(String.Format("{0} failed loading Driver API. ErrorCode={1:X8}h", [GetType]().Name, Marshal.GetLastWin32Error())) success = driverAPI.Init(mHandleStruct, DevInfo) If Not success Then Throw New Exception(String.Format("{0} failed initializing usb device. ErrorCode={1:X8}h", [GetType]().Name, Marshal.GetLastWin32Error())) Call Debug.Print("{0} Init: handle 0x{1:X16}", [GetType]().Name, mHandleStruct.Pointer.ToInt64()) Return True End Function ''' Claims the specified interface by number or index. Public Overridable Function ClaimInterface(ByVal NumberOrIndex As Byte, ByVal IsIndex As Boolean) As Boolean Return driverAPI.ClaimInterface(mHandleStruct, NumberOrIndex, IsIndex) End Function ''' Releases the specified interface by number or index. Public Overridable Function ReleaseInterface(ByVal NumberOrIndex As Byte, ByVal IsIndex As Boolean) As Boolean Return driverAPI.ReleaseInterface(mHandleStruct, NumberOrIndex, IsIndex) End Function ''' Sets the alternate setting of the specified interface. Public Overridable Function SetAltInterface(ByVal NumberOrIndex As Byte, ByVal IsIndex As Boolean, ByVal AltSettingNumber As Byte) As Boolean Return driverAPI.SetAltInterface(mHandleStruct, NumberOrIndex, IsIndex, AltSettingNumber) End Function ''' Gets the alternate setting for the specified interface. Public Overridable Function GetAltInterface(ByVal NumberOrIndex As Byte, ByVal IsIndex As Boolean, ByRef AltSettingNumber As Byte) As Boolean Return driverAPI.GetAltInterface(mHandleStruct, NumberOrIndex, IsIndex, AltSettingNumber) End Function ''' Gets the requested descriptor. This is a synchronous operation. Public Overridable Function GetDescriptor(ByVal DescriptorType As Byte, ByVal Index As Byte, ByVal LanguageID As Integer, ByVal Buffer As IntPtr, ByVal BufferLength As UInteger, ByRef LengthTransferred As UInteger) As Boolean Return driverAPI.GetDescriptor(mHandleStruct, DescriptorType, Index, LanguageID, Buffer, BufferLength, LengthTransferred) End Function ''' Gets the requested descriptor. This is a synchronous operation. Public Overridable Function GetDescriptor(ByVal DescriptorType As Byte, ByVal Index As Byte, ByVal LanguageID As Integer, ByVal Buffer As Array, ByVal BufferLength As UInteger, ByRef LengthTransferred As UInteger) As Boolean Return driverAPI.GetDescriptor(mHandleStruct, DescriptorType, Index, LanguageID, Marshal.UnsafeAddrOfPinnedArrayElement(Buffer, 0), BufferLength, LengthTransferred) End Function ''' Transmits control data over a default control endpoint. Public Overridable Function ControlTransfer(ByVal SetupPacket As WINUSB_SETUP_PACKET, ByVal Buffer As IntPtr, ByVal BufferLength As UInteger, ByRef LengthTransferred As UInteger, ByVal Overlapped As IntPtr) As Boolean Return driverAPI.ControlTransfer(mHandleStruct, SetupPacket, Buffer, BufferLength, LengthTransferred, Overlapped) End Function ''' Transmits control data over a default control endpoint. Public Overridable Function ControlTransfer(ByVal SetupPacket As WINUSB_SETUP_PACKET, ByVal Buffer As Array, ByVal BufferLength As UInteger, ByRef LengthTransferred As UInteger, ByVal Overlapped As IntPtr) As Boolean Return driverAPI.ControlTransfer(mHandleStruct, SetupPacket, Marshal.UnsafeAddrOfPinnedArrayElement(Buffer, 0), BufferLength, LengthTransferred, Overlapped) End Function ''' Transmits control data over a default control endpoint. Public Overridable Function ControlTransfer(ByVal SetupPacket As WINUSB_SETUP_PACKET, ByVal Buffer As Array, ByVal BufferLength As UInteger, ByRef LengthTransferred As UInteger, ByVal Overlapped As KOVL_HANDLE) As Boolean Return driverAPI.ControlTransfer(mHandleStruct, SetupPacket, Marshal.UnsafeAddrOfPinnedArrayElement(Buffer, 0), BufferLength, LengthTransferred, Overlapped.Pointer) End Function ''' Transmits control data over a default control endpoint. Public Overridable Function ControlTransfer(ByVal SetupPacket As WINUSB_SETUP_PACKET, ByVal Buffer As IntPtr, ByVal BufferLength As UInteger, ByRef LengthTransferred As UInteger, ByVal Overlapped As KOVL_HANDLE) As Boolean Return driverAPI.ControlTransfer(mHandleStruct, SetupPacket, Buffer, BufferLength, LengthTransferred, Overlapped.Pointer) End Function ''' Sets the power policy for a device. Public Overridable Function SetPowerPolicy(ByVal PolicyType As UInteger, ByVal ValueLength As UInteger, ByVal Value As IntPtr) As Boolean Return driverAPI.SetPowerPolicy(mHandleStruct, PolicyType, ValueLength, Value) End Function ''' Sets the power policy for a device. Public Overridable Function SetPowerPolicy(ByVal PolicyType As UInteger, ByVal ValueLength As UInteger, ByVal Value As Array) As Boolean Return driverAPI.SetPowerPolicy(mHandleStruct, PolicyType, ValueLength, Marshal.UnsafeAddrOfPinnedArrayElement(Value, 0)) End Function ''' Gets the power policy for a device. Public Overridable Function GetPowerPolicy(ByVal PolicyType As UInteger, ByRef ValueLength As UInteger, ByVal Value As IntPtr) As Boolean Return driverAPI.GetPowerPolicy(mHandleStruct, PolicyType, ValueLength, Value) End Function ''' Gets the power policy for a device. Public Overridable Function GetPowerPolicy(ByVal PolicyType As UInteger, ByRef ValueLength As UInteger, ByVal Value As Array) As Boolean Return driverAPI.GetPowerPolicy(mHandleStruct, PolicyType, ValueLength, Marshal.UnsafeAddrOfPinnedArrayElement(Value, 0)) End Function ''' Sets the device configuration number. Public Overridable Function SetConfiguration(ByVal ConfigurationNumber As Byte) As Boolean Return driverAPI.SetConfiguration(mHandleStruct, ConfigurationNumber) End Function ''' Gets the device current configuration number. Public Overridable Function GetConfiguration( ByRef ConfigurationNumber As Byte) As Boolean Return driverAPI.GetConfiguration(mHandleStruct, ConfigurationNumber) End Function ''' Resets the usb device of the specified interface handle. (port cycle). Public Overridable Function ResetDevice() As Boolean Return driverAPI.ResetDevice(mHandleStruct) End Function ''' Creates a libusbK handle for the device specified by a file handle. Protected Function Initialize(ByVal DeviceHandle As IntPtr, ByVal driverID As KUSB_DRVID) As Boolean Dim success = LibK_LoadDriverAPI(driverAPI, driverID) If Not success Then Throw New Exception(String.Format("{0} failed loading Driver API. ErrorCode={1:X8}h", [GetType]().Name, Marshal.GetLastWin32Error())) success = driverAPI.Initialize(DeviceHandle, mHandleStruct) If Not success Then Throw New Exception(String.Format("{0} failed initializing usb device. ErrorCode={1:X8}h", [GetType]().Name, Marshal.GetLastWin32Error())) Call Debug.Print("{0} Init: handle 0x{1:X16}", [GetType]().Name, mHandleStruct.Pointer.ToInt64()) Return True End Function ''' Selects the specified interface by number or index as the current interface. Public Overridable Function SelectInterface(ByVal NumberOrIndex As Byte, ByVal IsIndex As Boolean) As Boolean Return driverAPI.SelectInterface(mHandleStruct, NumberOrIndex, IsIndex) End Function ''' Retrieves a handle for an associated interface. Public Overridable Function GetAssociatedInterface(ByVal AssociatedInterfaceIndex As Byte, ByRef AssociatedInterfaceHandle As KUSB_HANDLE) As Boolean Return driverAPI.GetAssociatedInterface(mHandleStruct, AssociatedInterfaceIndex, AssociatedInterfaceHandle) End Function ''' Clones the specified interface handle. Public Overridable Function Clone( ByRef DstInterfaceHandle As KUSB_HANDLE) As Boolean Return driverAPI.Clone(mHandleStruct, DstInterfaceHandle) End Function ''' ''' Retrieves the interface descriptor for the specified alternate interface settings for a particular interface ''' handle. ''' Public Overridable Function QueryInterfaceSettings(ByVal AltSettingIndex As Byte, ByRef UsbAltInterfaceDescriptor As USB_INTERFACE_DESCRIPTOR) As Boolean Return driverAPI.QueryInterfaceSettings(mHandleStruct, AltSettingIndex, UsbAltInterfaceDescriptor) End Function ''' Retrieves information about the physical device that is associated with a libusbK handle. Public Overridable Function QueryDeviceInformation(ByVal InformationType As UInteger, ByRef BufferLength As UInteger, ByVal Buffer As IntPtr) As Boolean Return driverAPI.QueryDeviceInformation(mHandleStruct, InformationType, BufferLength, Buffer) End Function ''' Sets the alternate setting of an interface. Public Overridable Function SetCurrentAlternateSetting(ByVal AltSettingNumber As Byte) As Boolean Return driverAPI.SetCurrentAlternateSetting(mHandleStruct, AltSettingNumber) End Function ''' Gets the current alternate interface setting for an interface. Public Overridable Function GetCurrentAlternateSetting( ByRef AltSettingNumber As Byte) As Boolean Return driverAPI.GetCurrentAlternateSetting(mHandleStruct, AltSettingNumber) End Function ''' Retrieves information about a pipe that is associated with an interface. Public Overridable Function QueryPipe(ByVal AltSettingNumber As Byte, ByVal PipeIndex As Byte, ByRef PipeInformation As WINUSB_PIPE_INFORMATION) As Boolean Return driverAPI.QueryPipe(mHandleStruct, AltSettingNumber, PipeIndex, PipeInformation) End Function ''' Retrieves information about a pipe that is associated with an interface. Public Overridable Function QueryPipeEx(ByVal AltSettingNumber As Byte, ByVal PipeIndex As Byte, ByRef PipeInformationEx As WINUSB_PIPE_INFORMATION_EX) As Boolean Return driverAPI.QueryPipeEx(mHandleStruct, AltSettingNumber, PipeIndex, PipeInformationEx) End Function ''' Retrieves a pipes super speed endpoint companion descriptor associated with an interface. Public Overridable Function GetSuperSpeedPipeCompanionDescriptor(ByVal AltSettingNumber As Byte, ByVal PipeIndex As Byte, ByRef PipeCompanionDescriptor As USB_SUPERSPEED_ENDPOINT_COMPANION_DESCRIPTOR) As Boolean Return driverAPI.GetSuperSpeedPipeCompanionDescriptor(mHandleStruct, AltSettingNumber, PipeIndex, PipeCompanionDescriptor) End Function ''' ''' Sets the policy for a specific pipe associated with an endpoint on the device. This is a synchronous ''' operation. ''' Public Overridable Function SetPipePolicy(ByVal PipeID As Byte, ByVal PolicyType As UInteger, ByVal ValueLength As UInteger, ByVal Value As IntPtr) As Boolean Return driverAPI.SetPipePolicy(mHandleStruct, PipeID, PolicyType, ValueLength, Value) End Function ''' ''' Sets the policy for a specific pipe associated with an endpoint on the device. This is a synchronous ''' operation. ''' Public Overridable Function SetPipePolicy(ByVal PipeID As Byte, ByVal PolicyType As UInteger, ByVal ValueLength As UInteger, ByVal Value As Array) As Boolean Return driverAPI.SetPipePolicy(mHandleStruct, PipeID, PolicyType, ValueLength, Marshal.UnsafeAddrOfPinnedArrayElement(Value, 0)) End Function ''' Gets the policy for a specific pipe (endpoint). Public Overridable Function GetPipePolicy(ByVal PipeID As Byte, ByVal PolicyType As UInteger, ByRef ValueLength As UInteger, ByVal Value As IntPtr) As Boolean Return driverAPI.GetPipePolicy(mHandleStruct, PipeID, PolicyType, ValueLength, Value) End Function ''' Gets the policy for a specific pipe (endpoint). Public Overridable Function GetPipePolicy(ByVal PipeID As Byte, ByVal PolicyType As UInteger, ByRef ValueLength As UInteger, ByVal Value As Array) As Boolean Return driverAPI.GetPipePolicy(mHandleStruct, PipeID, PolicyType, ValueLength, Marshal.UnsafeAddrOfPinnedArrayElement(Value, 0)) End Function ''' Reads data from the specified pipe. Public Overridable Function ReadPipe(ByVal PipeID As Byte, ByVal Buffer As IntPtr, ByVal BufferLength As UInteger, ByRef LengthTransferred As UInteger, ByVal Overlapped As IntPtr) As Boolean Return driverAPI.ReadPipe(mHandleStruct, PipeID, Buffer, BufferLength, LengthTransferred, Overlapped) End Function ''' Reads data from the specified pipe. Public Overridable Function ReadPipe(ByVal PipeID As Byte, ByVal Buffer As Array, ByVal BufferLength As UInteger, ByRef LengthTransferred As UInteger, ByVal Overlapped As IntPtr) As Boolean Return driverAPI.ReadPipe(mHandleStruct, PipeID, Marshal.UnsafeAddrOfPinnedArrayElement(Buffer, 0), BufferLength, LengthTransferred, Overlapped) End Function ''' Reads data from the specified pipe. Public Overridable Function ReadPipe(ByVal PipeID As Byte, ByVal Buffer As Array, ByVal BufferLength As UInteger, ByRef LengthTransferred As UInteger, ByVal Overlapped As KOVL_HANDLE) As Boolean Return driverAPI.ReadPipe(mHandleStruct, PipeID, Marshal.UnsafeAddrOfPinnedArrayElement(Buffer, 0), BufferLength, LengthTransferred, Overlapped.Pointer) End Function ''' Reads data from the specified pipe. Public Overridable Function ReadPipe(ByVal PipeID As Byte, ByVal Buffer As IntPtr, ByVal BufferLength As UInteger, ByRef LengthTransferred As UInteger, ByVal Overlapped As KOVL_HANDLE) As Boolean Return driverAPI.ReadPipe(mHandleStruct, PipeID, Buffer, BufferLength, LengthTransferred, Overlapped.Pointer) End Function ''' Writes data to a pipe. Public Overridable Function WritePipe(ByVal PipeID As Byte, ByVal Buffer As IntPtr, ByVal BufferLength As UInteger, ByRef LengthTransferred As UInteger, ByVal Overlapped As IntPtr) As Boolean Return driverAPI.WritePipe(mHandleStruct, PipeID, Buffer, BufferLength, LengthTransferred, Overlapped) End Function ''' Writes data to a pipe. Public Overridable Function WritePipe(ByVal PipeID As Byte, ByVal Buffer As Array, ByVal BufferLength As UInteger, ByRef LengthTransferred As UInteger, ByVal Overlapped As IntPtr) As Boolean Return driverAPI.WritePipe(mHandleStruct, PipeID, Marshal.UnsafeAddrOfPinnedArrayElement(Buffer, 0), BufferLength, LengthTransferred, Overlapped) End Function ''' Writes data to a pipe. Public Overridable Function WritePipe(ByVal PipeID As Byte, ByVal Buffer As Array, ByVal BufferLength As UInteger, ByRef LengthTransferred As UInteger, ByVal Overlapped As KOVL_HANDLE) As Boolean Return driverAPI.WritePipe(mHandleStruct, PipeID, Marshal.UnsafeAddrOfPinnedArrayElement(Buffer, 0), BufferLength, LengthTransferred, Overlapped.Pointer) End Function ''' Writes data to a pipe. Public Overridable Function WritePipe(ByVal PipeID As Byte, ByVal Buffer As IntPtr, ByVal BufferLength As UInteger, ByRef LengthTransferred As UInteger, ByVal Overlapped As KOVL_HANDLE) As Boolean Return driverAPI.WritePipe(mHandleStruct, PipeID, Buffer, BufferLength, LengthTransferred, Overlapped.Pointer) End Function ''' Resets the data toggle and clears the stall condition on a pipe. Public Overridable Function ResetPipe(ByVal PipeID As Byte) As Boolean Return driverAPI.ResetPipe(mHandleStruct, PipeID) End Function ''' Aborts all of the pending transfers for a pipe. Public Overridable Function AbortPipe(ByVal PipeID As Byte) As Boolean Return driverAPI.AbortPipe(mHandleStruct, PipeID) End Function ''' Discards any data that is cached in a pipe. Public Overridable Function FlushPipe(ByVal PipeID As Byte) As Boolean Return driverAPI.FlushPipe(mHandleStruct, PipeID) End Function ''' Reads from an isochronous pipe. Public Overridable Function IsoReadPipe(ByVal PipeID As Byte, ByVal Buffer As IntPtr, ByVal BufferLength As UInteger, ByVal Overlapped As IntPtr, ByVal IsoContext As KISO_CONTEXT) As Boolean Return driverAPI.IsoReadPipe(mHandleStruct, PipeID, Buffer, BufferLength, Overlapped, IsoContext) End Function ''' Reads from an isochronous pipe. Public Overridable Function IsoReadPipe(ByVal PipeID As Byte, ByVal Buffer As Array, ByVal BufferLength As UInteger, ByVal Overlapped As IntPtr, ByVal IsoContext As KISO_CONTEXT) As Boolean Return driverAPI.IsoReadPipe(mHandleStruct, PipeID, Marshal.UnsafeAddrOfPinnedArrayElement(Buffer, 0), BufferLength, Overlapped, IsoContext) End Function ''' Reads from an isochronous pipe. Public Overridable Function IsoReadPipe(ByVal PipeID As Byte, ByVal Buffer As Array, ByVal BufferLength As UInteger, ByVal Overlapped As KOVL_HANDLE, ByVal IsoContext As KISO_CONTEXT) As Boolean Return driverAPI.IsoReadPipe(mHandleStruct, PipeID, Marshal.UnsafeAddrOfPinnedArrayElement(Buffer, 0), BufferLength, Overlapped.Pointer, IsoContext) End Function ''' Reads from an isochronous pipe. Public Overridable Function IsoReadPipe(ByVal PipeID As Byte, ByVal Buffer As IntPtr, ByVal BufferLength As UInteger, ByVal Overlapped As KOVL_HANDLE, ByVal IsoContext As KISO_CONTEXT) As Boolean Return driverAPI.IsoReadPipe(mHandleStruct, PipeID, Buffer, BufferLength, Overlapped.Pointer, IsoContext) End Function ''' Writes to an isochronous pipe. Public Overridable Function IsoWritePipe(ByVal PipeID As Byte, ByVal Buffer As IntPtr, ByVal BufferLength As UInteger, ByVal Overlapped As IntPtr, ByVal IsoContext As KISO_CONTEXT) As Boolean Return driverAPI.IsoWritePipe(mHandleStruct, PipeID, Buffer, BufferLength, Overlapped, IsoContext) End Function ''' Writes to an isochronous pipe. Public Overridable Function IsoWritePipe(ByVal PipeID As Byte, ByVal Buffer As Array, ByVal BufferLength As UInteger, ByVal Overlapped As IntPtr, ByVal IsoContext As KISO_CONTEXT) As Boolean Return driverAPI.IsoWritePipe(mHandleStruct, PipeID, Marshal.UnsafeAddrOfPinnedArrayElement(Buffer, 0), BufferLength, Overlapped, IsoContext) End Function ''' Writes to an isochronous pipe. Public Overridable Function IsoWritePipe(ByVal PipeID As Byte, ByVal Buffer As Array, ByVal BufferLength As UInteger, ByVal Overlapped As KOVL_HANDLE, ByVal IsoContext As KISO_CONTEXT) As Boolean Return driverAPI.IsoWritePipe(mHandleStruct, PipeID, Marshal.UnsafeAddrOfPinnedArrayElement(Buffer, 0), BufferLength, Overlapped.Pointer, IsoContext) End Function ''' Writes to an isochronous pipe. Public Overridable Function IsoWritePipe(ByVal PipeID As Byte, ByVal Buffer As IntPtr, ByVal BufferLength As UInteger, ByVal Overlapped As KOVL_HANDLE, ByVal IsoContext As KISO_CONTEXT) As Boolean Return driverAPI.IsoWritePipe(mHandleStruct, PipeID, Buffer, BufferLength, Overlapped.Pointer, IsoContext) End Function ''' Retrieves the current USB frame number. Public Overridable Function GetCurrentFrameNumber( ByRef FrameNumber As UInteger) As Boolean Return driverAPI.GetCurrentFrameNumber(mHandleStruct, FrameNumber) End Function ''' Reads from an isochronous pipe. Supports LibusbK or WinUsb Public Overridable Function IsochReadPipe(ByVal IsochHandle As KISOCH_HANDLE, ByVal DataLength As UInteger, ByRef FrameNumber As UInteger, ByVal NumberOfPackets As UInteger, ByVal Overlapped As IntPtr) As Boolean Return driverAPI.IsochReadPipe(IsochHandle, DataLength, FrameNumber, NumberOfPackets, Overlapped) End Function ''' Reads from an isochronous pipe. Supports LibusbK or WinUsb Public Overridable Function IsochReadPipe(ByVal IsochHandle As KISOCH_HANDLE, ByVal DataLength As UInteger, ByRef FrameNumber As UInteger, ByVal NumberOfPackets As UInteger, ByVal Overlapped As KOVL_HANDLE) As Boolean Return driverAPI.IsochReadPipe(IsochHandle, DataLength, FrameNumber, NumberOfPackets, Overlapped.Pointer) End Function ''' Writes to an isochronous pipe. Supports LibusbK or WinUsb Public Overridable Function IsochWritePipe(ByVal IsochHandle As KISOCH_HANDLE, ByVal DataLength As UInteger, ByRef FrameNumber As UInteger, ByVal NumberOfPackets As UInteger, ByVal Overlapped As IntPtr) As Boolean Return driverAPI.IsochWritePipe(IsochHandle, DataLength, FrameNumber, NumberOfPackets, Overlapped) End Function ''' Writes to an isochronous pipe. Supports LibusbK or WinUsb Public Overridable Function IsochWritePipe(ByVal IsochHandle As KISOCH_HANDLE, ByVal DataLength As UInteger, ByRef FrameNumber As UInteger, ByVal NumberOfPackets As UInteger, ByVal Overlapped As KOVL_HANDLE) As Boolean Return driverAPI.IsochWritePipe(IsochHandle, DataLength, FrameNumber, NumberOfPackets, Overlapped.Pointer) End Function ''' Retrieves the results of an overlapped operation on the specified libusbK handle. Public Overridable Function GetOverlappedResult(ByVal Overlapped As IntPtr, ByRef lpNumberOfBytesTransferred As UInteger, ByVal bWait As Boolean) As Boolean Return driverAPI.GetOverlappedResult(mHandleStruct, Overlapped, lpNumberOfBytesTransferred, bWait) End Function ''' Retrieves the results of an overlapped operation on the specified libusbK handle. Public Overridable Function GetOverlappedResult(ByVal Overlapped As KOVL_HANDLE, ByRef lpNumberOfBytesTransferred As UInteger, ByVal bWait As Boolean) As Boolean Return driverAPI.GetOverlappedResult(mHandleStruct, Overlapped.Pointer, lpNumberOfBytesTransferred, bWait) End Function ''' Gets a USB device (driver specific) property from usb handle. Public Overridable Function GetProperty(ByVal PropertyType As KUSB_PROPERTY, ByRef PropertySize As UInteger, ByVal Value As IntPtr) As Boolean Return driverAPI.GetProperty(mHandleStruct, PropertyType, PropertySize, Value) End Function ''' Gets a USB device (driver specific) property from usb handle. Public Overridable Function GetProperty(ByVal PropertyType As KUSB_PROPERTY, ByRef PropertySize As UInteger, ByVal Value As Array) As Boolean Return driverAPI.GetProperty(mHandleStruct, PropertyType, PropertySize, Marshal.UnsafeAddrOfPinnedArrayElement(Value, 0)) End Function End Class Public Class OvlK Implements IDisposable Protected mbDisposed As Boolean Protected mHandleStruct As KOVL_POOL_HANDLE Protected Sub New() End Sub ''' Creates a new overlapped pool. Public Sub New(ByVal UsbHandle As KUSB_HANDLE, ByVal MaxOverlappedCount As Integer, ByVal Flags As KOVL_POOL_FLAG) Dim success = OvlK_Init(mHandleStruct, UsbHandle, MaxOverlappedCount, Flags) If Not success Then Throw New Exception(String.Format("{0} failed initializing. ErrorCode={1:X8}h", [GetType]().Name, Marshal.GetLastWin32Error())) Call Debug.Print("{0} Init: handle 0x{1:X16}", [GetType]().Name, mHandleStruct.Pointer.ToInt64()) End Sub ''' Gets the handle class structure. Public ReadOnly Property Handle As KOVL_POOL_HANDLE Get Return mHandleStruct End Get End Property ''' Explicitly closes and frees the handle. Public Overridable Sub Dispose() Implements IDisposable.Dispose Dispose(True) GC.SuppressFinalize(Me) End Sub Protected Overrides Sub Finalize() Dispose(False) End Sub ''' Calls the dispose method. Public Overridable Sub Free() Dispose() End Sub Protected Overridable Sub Dispose(ByVal disposing As Boolean) If Not mbDisposed Then If mHandleStruct.Pointer <> IntPtr.Zero Then OvlK_Free(mHandleStruct) Call Debug.Print("{0} Dispose: Freed Handle:{1:X16}h Explicit:{2}", [GetType]().Name, mHandleStruct.Pointer.ToInt64(), disposing) Else Call Debug.Print("{0} Dispose: [WARNING] Handle is null", [GetType]().Name) End If mHandleStruct = New KOVL_POOL_HANDLE(IntPtr.Zero) mbDisposed = True End If End Sub ''' Gets a preallocated \c OverlappedK structure from the specified/default pool. Public Overridable Function Acquire( ByRef OverlappedK As KOVL_HANDLE) As Boolean Return OvlK_Acquire(OverlappedK, mHandleStruct) End Function ''' Returns an \c OverlappedK structure to it's pool. Public Shared Function Release(ByVal OverlappedK As KOVL_HANDLE) As Boolean Return OvlK_Release(OverlappedK) End Function ''' Creates a new overlapped pool. Protected Function Init(ByVal UsbHandle As KUSB_HANDLE, ByVal MaxOverlappedCount As Integer, ByVal Flags As KOVL_POOL_FLAG) As Boolean Dim success = OvlK_Init(mHandleStruct, UsbHandle, MaxOverlappedCount, Flags) If Not success Then Throw New Exception(String.Format("{0} failed initializing. ErrorCode={1:X8}h", [GetType]().Name, Marshal.GetLastWin32Error())) Call Debug.Print("{0} Init: handle 0x{1:X16}", [GetType]().Name, mHandleStruct.Pointer.ToInt64()) Return True End Function ''' Returns the internal event handle used to signal IO operations. Public Shared Function GetEventHandle(ByVal OverlappedK As KOVL_HANDLE) As IntPtr Return OvlK_GetEventHandle(OverlappedK) End Function ''' Waits for overlapped I/O completion, and performs actions specified in \c WaitFlags. Public Shared Function Wait(ByVal OverlappedK As KOVL_HANDLE, ByVal TimeoutMS As Integer, ByVal WaitFlags As KOVL_WAIT_FLAG, ByRef TransferredLength As UInteger) As Boolean Return OvlK_Wait(OverlappedK, TimeoutMS, WaitFlags, TransferredLength) End Function ''' ''' Waits for overlapped I/O completion on the oldest acquired OverlappedK handle and performs actions specified ''' in \c WaitFlags. ''' Public Overridable Function WaitOldest( ByRef OverlappedK As KOVL_HANDLE, ByVal TimeoutMS As Integer, ByVal WaitFlags As KOVL_WAIT_FLAG, ByRef TransferredLength As UInteger) As Boolean Return OvlK_WaitOldest(mHandleStruct, OverlappedK, TimeoutMS, WaitFlags, TransferredLength) End Function ''' Waits for overlapped I/O completion, cancels on a timeout error. Public Shared Function WaitOrCancel(ByVal OverlappedK As KOVL_HANDLE, ByVal TimeoutMS As Integer, ByRef TransferredLength As UInteger) As Boolean Return OvlK_WaitOrCancel(OverlappedK, TimeoutMS, TransferredLength) End Function ''' ''' Waits for overlapped I/O completion, cancels on a timeout error and always releases the OvlK handle back to ''' its pool. ''' Public Shared Function WaitAndRelease(ByVal OverlappedK As KOVL_HANDLE, ByVal TimeoutMS As Integer, ByRef TransferredLength As UInteger) As Boolean Return OvlK_WaitAndRelease(OverlappedK, TimeoutMS, TransferredLength) End Function ''' Checks for i/o completion; returns immediately. (polling) Public Shared Function IsComplete(ByVal OverlappedK As KOVL_HANDLE) As Boolean Return OvlK_IsComplete(OverlappedK) End Function ''' Initializes an overlappedK for re-use. The overlappedK is not return to its pool. Public Shared Function ReUse(ByVal OverlappedK As KOVL_HANDLE) As Boolean Return OvlK_ReUse(OverlappedK) End Function End Class Public Class StmK Implements IDisposable Protected mbDisposed As Boolean Protected mHandleStruct As KSTM_HANDLE Protected Sub New() End Sub ''' Initializes a new uni-directional pipe stream. Public Sub New(ByVal UsbHandle As KUSB_HANDLE, ByVal PipeID As Byte, ByVal MaxTransferSize As Integer, ByVal MaxPendingTransfers As Integer, ByVal MaxPendingIO As Integer, ByRef Callbacks As KSTM_CALLBACK, ByVal Flags As KSTM_FLAG) Dim success = StmK_Init(mHandleStruct, UsbHandle, PipeID, MaxTransferSize, MaxPendingTransfers, MaxPendingIO, Callbacks, Flags) If Not success Then Throw New Exception(String.Format("{0} failed initializing. ErrorCode={1:X8}h", [GetType]().Name, Marshal.GetLastWin32Error())) Call Debug.Print("{0} Init: handle 0x{1:X16}", [GetType]().Name, mHandleStruct.Pointer.ToInt64()) End Sub ''' Gets the handle class structure. Public ReadOnly Property Handle As KSTM_HANDLE Get Return mHandleStruct End Get End Property ''' Explicitly closes and frees the handle. Public Overridable Sub Dispose() Implements IDisposable.Dispose Dispose(True) GC.SuppressFinalize(Me) End Sub Protected Overrides Sub Finalize() Dispose(False) End Sub ''' Calls the dispose method. Public Overridable Sub Free() Dispose() End Sub Protected Overridable Sub Dispose(ByVal disposing As Boolean) If Not mbDisposed Then If mHandleStruct.Pointer <> IntPtr.Zero Then StmK_Free(mHandleStruct) Call Debug.Print("{0} Dispose: Freed Handle:{1:X16}h Explicit:{2}", [GetType]().Name, mHandleStruct.Pointer.ToInt64(), disposing) Else Call Debug.Print("{0} Dispose: [WARNING] Handle is null", [GetType]().Name) End If mHandleStruct = New KSTM_HANDLE(IntPtr.Zero) mbDisposed = True End If End Sub ''' Initializes a new uni-directional pipe stream. Protected Function Init(ByVal UsbHandle As KUSB_HANDLE, ByVal PipeID As Byte, ByVal MaxTransferSize As Integer, ByVal MaxPendingTransfers As Integer, ByVal MaxPendingIO As Integer, ByRef Callbacks As KSTM_CALLBACK, ByVal Flags As KSTM_FLAG) As Boolean Dim success = StmK_Init(mHandleStruct, UsbHandle, PipeID, MaxTransferSize, MaxPendingTransfers, MaxPendingIO, Callbacks, Flags) If Not success Then Throw New Exception(String.Format("{0} failed initializing. ErrorCode={1:X8}h", [GetType]().Name, Marshal.GetLastWin32Error())) Call Debug.Print("{0} Init: handle 0x{1:X16}", [GetType]().Name, mHandleStruct.Pointer.ToInt64()) Return True End Function ''' Starts the internal stream thread. Public Overridable Function Start() As Boolean Return StmK_Start(mHandleStruct) End Function ''' Stops the internal stream thread. Public Overridable Function [Stop](ByVal TimeoutCancelMS As Integer) As Boolean Return StmK_Stop(mHandleStruct, TimeoutCancelMS) End Function ''' Reads data from the stream buffer. Public Overridable Function Read(ByVal Buffer As IntPtr, ByVal Offset As Integer, ByVal Length As Integer, ByRef TransferredLength As UInteger) As Boolean Return StmK_Read(mHandleStruct, Buffer, Offset, Length, TransferredLength) End Function ''' Reads data from the stream buffer. Public Overridable Function Read(ByVal Buffer As Array, ByVal Offset As Integer, ByVal Length As Integer, ByRef TransferredLength As UInteger) As Boolean Return StmK_Read(mHandleStruct, Marshal.UnsafeAddrOfPinnedArrayElement(Buffer, 0), Offset, Length, TransferredLength) End Function ''' Writes data to the stream buffer. Public Overridable Function Write(ByVal Buffer As IntPtr, ByVal Offset As Integer, ByVal Length As Integer, ByRef TransferredLength As UInteger) As Boolean Return StmK_Write(mHandleStruct, Buffer, Offset, Length, TransferredLength) End Function ''' Writes data to the stream buffer. Public Overridable Function Write(ByVal Buffer As Array, ByVal Offset As Integer, ByVal Length As Integer, ByRef TransferredLength As UInteger) As Boolean Return StmK_Write(mHandleStruct, Marshal.UnsafeAddrOfPinnedArrayElement(Buffer, 0), Offset, Length, TransferredLength) End Function End Class Public Class IsoK Implements IDisposable Private Shared ReadOnly ofsFlags As Integer = Marshal.OffsetOf(GetType(KISO_CONTEXT_MAP), "Flags").ToInt32() Private Shared ReadOnly ofsStartFrame As Integer = Marshal.OffsetOf(GetType(KISO_CONTEXT_MAP), "StartFrame").ToInt32() Private Shared ReadOnly ofsErrorCount As Integer = Marshal.OffsetOf(GetType(KISO_CONTEXT_MAP), "ErrorCount").ToInt32() Private Shared ReadOnly ofsNumberOfPackets As Integer = Marshal.OffsetOf(GetType(KISO_CONTEXT_MAP), "NumberOfPackets").ToInt32() Private Shared ReadOnly ofsUrbHdrStatus As Integer = Marshal.OffsetOf(GetType(KISO_CONTEXT_MAP), "UrbHdrStatus").ToInt32() Protected mbDisposed As Boolean Protected mHandleStruct As KISO_CONTEXT Protected Sub New() End Sub ''' Creates a new isochronous transfer context for libusbK only. Public Sub New(ByVal NumberOfPackets As Integer, ByVal StartFrame As Integer) Dim success = IsoK_Init(mHandleStruct, NumberOfPackets, StartFrame) If Not success Then Throw New Exception(String.Format("{0} failed initializing. ErrorCode={1:X8}h", [GetType]().Name, Marshal.GetLastWin32Error())) Call Debug.Print("{0} Init: handle 0x{1:X16}", [GetType]().Name, mHandleStruct.Pointer.ToInt64()) End Sub ''' Gets the handle class structure. Public ReadOnly Property Handle As KISO_CONTEXT Get Return mHandleStruct End Get End Property ''' Additional ISO transfer flags. See \ref KISO_FLAG. Public Property Flags As KISO_FLAG Get Return Marshal.ReadInt32(mHandleStruct.Pointer, ofsFlags) End Get Set(ByVal value As KISO_FLAG) Marshal.WriteInt32(mHandleStruct.Pointer, ofsFlags, value) End Set End Property ''' Specifies the frame number that the transfer should begin on (0 for ASAP). Public Property StartFrame As UInteger Get Return Marshal.ReadInt32(mHandleStruct.Pointer, ofsStartFrame) End Get Set(ByVal value As UInteger) Marshal.WriteInt32(mHandleStruct.Pointer, ofsStartFrame, CInt(value)) End Set End Property ''' ''' Contains the number of packets that completed with an error condition on return from the host controller ''' driver. ''' Public Property ErrorCount As Short Get Return Marshal.ReadInt16(mHandleStruct.Pointer, ofsErrorCount) End Get Set(ByVal value As Short) Marshal.WriteInt16(mHandleStruct.Pointer, ofsErrorCount, value) End Set End Property ''' Specifies the number of packets that are described by the variable-length array member \c IsoPacket. Public Property NumberOfPackets As Short Get Return Marshal.ReadInt16(mHandleStruct.Pointer, ofsNumberOfPackets) End Get Set(ByVal value As Short) Marshal.WriteInt16(mHandleStruct.Pointer, ofsNumberOfPackets, value) End Set End Property ''' Contains the URB Hdr.Status value on return from the host controller driver. Public Property UrbHdrStatus As UInteger Get Return Marshal.ReadInt32(mHandleStruct.Pointer, ofsUrbHdrStatus) End Get Set(ByVal value As UInteger) Marshal.WriteInt32(mHandleStruct.Pointer, ofsUrbHdrStatus, CInt(value)) End Set End Property ''' Explicitly closes and frees the handle. Public Overridable Sub Dispose() Implements IDisposable.Dispose Dispose(True) GC.SuppressFinalize(Me) End Sub Protected Overrides Sub Finalize() Dispose(False) End Sub ''' Calls the dispose method. Public Overridable Sub Free() Dispose() End Sub Protected Overridable Sub Dispose(ByVal disposing As Boolean) If Not mbDisposed Then If mHandleStruct.Pointer <> IntPtr.Zero Then IsoK_Free(mHandleStruct) Call Debug.Print("{0} Dispose: Freed Handle:{1:X16}h Explicit:{2}", [GetType]().Name, mHandleStruct.Pointer.ToInt64(), disposing) Else Call Debug.Print("{0} Dispose: [WARNING] Handle is null", [GetType]().Name) End If mHandleStruct = New KISO_CONTEXT(IntPtr.Zero) mbDisposed = True End If End Sub ''' Creates a new isochronous transfer context for libusbK only. Protected Function Init(ByVal NumberOfPackets As Integer, ByVal StartFrame As Integer) As Boolean Dim success = IsoK_Init(mHandleStruct, NumberOfPackets, StartFrame) If Not success Then Throw New Exception(String.Format("{0} failed initializing. ErrorCode={1:X8}h", [GetType]().Name, Marshal.GetLastWin32Error())) Call Debug.Print("{0} Init: handle 0x{1:X16}", [GetType]().Name, mHandleStruct.Pointer.ToInt64()) Return True End Function ''' Convenience function for setting the offset of all ISO packets of an isochronous transfer context. Public Overridable Function SetPackets(ByVal PacketSize As Integer) As Boolean Return IsoK_SetPackets(mHandleStruct, PacketSize) End Function ''' Convenience function for setting all fields of a \ref KISO_PACKET. Public Overridable Function SetPacket(ByVal PacketIndex As Integer, ByRef IsoPacket As KISO_PACKET) As Boolean Return IsoK_SetPacket(mHandleStruct, PacketIndex, IsoPacket) End Function ''' Convenience function for getting all fields of a \ref KISO_PACKET. Public Overridable Function GetPacket(ByVal PacketIndex As Integer, ByRef IsoPacket As KISO_PACKET) As Boolean Return IsoK_GetPacket(mHandleStruct, PacketIndex, IsoPacket) End Function ''' Convenience function for enumerating ISO packets of an isochronous transfer context. Public Overridable Function EnumPackets(ByVal pEnumPackets As KISO_ENUM_PACKETS_CB, ByVal StartPacketIndex As Integer, ByVal UserState As IntPtr) As Boolean Return IsoK_EnumPackets(mHandleStruct, pEnumPackets, StartPacketIndex, UserState) End Function ''' Convenience function for re-using an isochronous transfer context in a subsequent request. Public Overridable Function ReUse() As Boolean Return IsoK_ReUse(mHandleStruct) End Function Private Structure KISO_CONTEXT_MAP ''' Additional ISO transfer flags. See \ref KISO_FLAG. Private ReadOnly Flags As KISO_FLAG ''' Specifies the frame number that the transfer should begin on (0 for ASAP). Private ReadOnly StartFrame As UInteger ''' ''' Contains the number of packets that completed with an error condition on return from the host controller ''' driver. ''' Private ReadOnly ErrorCount As Short ''' Specifies the number of packets that are described by the variable-length array member \c IsoPacket. Private ReadOnly NumberOfPackets As Short ''' Contains the URB Hdr.Status value on return from the host controller driver. Private ReadOnly UrbHdrStatus As UInteger End Structure End Class Public Class IsochK Implements IDisposable Protected mbDisposed As Boolean Protected mHandleStruct As KISOCH_HANDLE Protected Sub New() End Sub ''' Creates a new isochronous transfer handle for libusbK or WinUSB. Public Sub New(ByVal InterfaceHandle As KUSB_HANDLE, ByVal PipeId As Byte, ByVal MaxNumberOfPackets As UInteger, ByVal TransferBuffer As IntPtr, ByVal TransferBufferSize As UInteger) Dim success = IsochK_Init(mHandleStruct, InterfaceHandle, PipeId, MaxNumberOfPackets, TransferBuffer, TransferBufferSize) If Not success Then Throw New Exception(String.Format("{0} failed initializing. ErrorCode={1:X8}h", [GetType]().Name, Marshal.GetLastWin32Error())) Call Debug.Print("{0} Init: handle 0x{1:X16}", [GetType]().Name, mHandleStruct.Pointer.ToInt64()) End Sub ''' Gets the handle class structure. Public ReadOnly Property Handle As KISOCH_HANDLE Get Return mHandleStruct End Get End Property ''' Explicitly closes and frees the handle. Public Overridable Sub Dispose() Implements IDisposable.Dispose Dispose(True) GC.SuppressFinalize(Me) End Sub Protected Overrides Sub Finalize() Dispose(False) End Sub ''' Calls the dispose method. Public Overridable Sub Free() Dispose() End Sub Protected Overridable Sub Dispose(ByVal disposing As Boolean) If Not mbDisposed Then If mHandleStruct.Pointer <> IntPtr.Zero Then IsochK_Free(mHandleStruct) Call Debug.Print("{0} Dispose: Freed Handle:{1:X16}h Explicit:{2}", [GetType]().Name, mHandleStruct.Pointer.ToInt64(), disposing) Else Call Debug.Print("{0} Dispose: [WARNING] Handle is null", [GetType]().Name) End If mHandleStruct = New KISOCH_HANDLE(IntPtr.Zero) mbDisposed = True End If End Sub ''' Creates a new isochronous transfer handle for libusbK or WinUSB. Protected Function Init(ByVal InterfaceHandle As KUSB_HANDLE, ByVal PipeId As Byte, ByVal MaxNumberOfPackets As UInteger, ByVal TransferBuffer As IntPtr, ByVal TransferBufferSize As UInteger) As Boolean Dim success = IsochK_Init(mHandleStruct, InterfaceHandle, PipeId, MaxNumberOfPackets, TransferBuffer, TransferBufferSize) If Not success Then Throw New Exception(String.Format("{0} failed initializing. ErrorCode={1:X8}h", [GetType]().Name, Marshal.GetLastWin32Error())) Call Debug.Print("{0} Init: handle 0x{1:X16}", [GetType]().Name, mHandleStruct.Pointer.ToInt64()) Return True End Function ''' Convenience function for setting the offsets and lengths of all ISO packets of an isochronous transfer handle. Public Overridable Function SetPacketOffsets(ByVal PacketSize As UInteger) As Boolean Return IsochK_SetPacketOffsets(mHandleStruct, PacketSize) End Function ''' Convenience function for setting all fields in an isochronous transfer packet. Public Overridable Function SetPacket(ByVal PacketIndex As UInteger, ByVal Offset As UInteger, ByVal Length As UInteger, ByVal Status As UInteger) As Boolean Return IsochK_SetPacket(mHandleStruct, PacketIndex, Offset, Length, Status) End Function ''' Convenience function for getting all fields in an isochronous transfer packet. Public Overridable Function GetPacket(ByVal PacketIndex As UInteger, ByRef Offset As UInteger, ByRef Length As UInteger, ByRef Status As UInteger) As Boolean Return IsochK_GetPacket(mHandleStruct, PacketIndex, Offset, Length, Status) End Function ''' Convenience function for enumerating ISO packets of an isochronous transfer context. Public Overridable Function EnumPackets(ByVal pEnumPackets As KISOCH_ENUM_PACKETS_CB, ByVal StartPacketIndex As UInteger, ByVal UserState As IntPtr) As Boolean Return IsochK_EnumPackets(mHandleStruct, pEnumPackets, StartPacketIndex, UserState) End Function ''' Helper function for isochronous packet/transfer calculations. Public Shared Function CalcPacketInformation(ByVal IsHighSpeed As Boolean, ByRef PipeInformationEx As WINUSB_PIPE_INFORMATION_EX, ByRef PacketInformation As KISOCH_PACKET_INFORMATION) As Boolean Return IsochK_CalcPacketInformation(IsHighSpeed, PipeInformationEx, PacketInformation) End Function ''' Gets the number of iso packets that will be used. Public Overridable Function GetNumberOfPackets( ByRef NumberOfPackets As UInteger) As Boolean Return IsochK_GetNumberOfPackets(mHandleStruct, NumberOfPackets) End Function ''' Sets the number of iso packets that will be used. Public Overridable Function SetNumberOfPackets(ByVal NumberOfPackets As UInteger) As Boolean Return IsochK_SetNumberOfPackets(mHandleStruct, NumberOfPackets) End Function End Class End Namespace