WINUSB.bi

For issues with communication ports, protocols, etc.
Post Reply
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

WINUSB.bi

Post by D.J.Peters »

Win Server 2003, 2008, VISTA, WinXP ,Win7

winusb.dll winusb.sys

file: WINUSB.b

Code: Select all

#ifndef __WINUSB_BI__
#define __WINUSB_BI__

#include once "windows.bi"

type  WINUSB_INTERFACE_HANDLE as PVOID
type PWINUSB_INTERFACE_HANDLE as WINUSB_INTERFACE_HANDLE ptr

type _WINUSB_SETUP_PACKET field = 1
  as  UCHAR   RequestType
  as  UCHAR   Request
  as  USHORT  Value
  as  USHORT  Index
  as  USHORT  Length
end type
type  WINUSB_SETUP_PACKET as _WINUSB_SETUP_PACKET
type PWINUSB_SETUP_PACKET as _WINUSB_SETUP_PACKET ptr

type _USB_DEVICE_DESCRIPTOR
  as UCHAR  bLength
  as UCHAR  bDescriptorType
  as USHORT bcdUSB
  as UCHAR  bDeviceClass
  as UCHAR  bDeviceSubClass
  as UCHAR  bDeviceProtocol
  as UCHAR  bMaxPacketSize0
  as USHORT idVendor
  as USHORT idProduct
  as USHORT bcdDevice
  as UCHAR  iManufacturer
  as UCHAR  iProduct
  as UCHAR  iSerialNumber
  as UCHAR  bNumConfigurations
end type
type  USB_DEVICE_DESCRIPTOR as _USB_DEVICE_DESCRIPTOR
type PUSB_DEVICE_DESCRIPTOR as _USB_DEVICE_DESCRIPTOR ptr

type _USB_INTERFACE_DESCRIPTOR
  as UCHAR bLength
  as UCHAR bDescriptorType
  as UCHAR bInterfaceNumber
  as UCHAR bAlternateSetting
  as UCHAR bNumEndpoints
  as UCHAR bInterfaceClass
  as UCHAR bInterfaceSubClass
  as UCHAR bInterfaceProtocol
  as UCHAR iInterface
end type
type  USB_INTERFACE_DESCRIPTOR as _USB_INTERFACE_DESCRIPTOR
type PUSB_INTERFACE_DESCRIPTOR as _USB_INTERFACE_DESCRIPTOR ptr

enum _USBD_PIPE_TYPE
  UsbdPipeTypeControl      = 0
  UsbdPipeTypeIsochronous  = 1
  UsbdPipeTypeBulk         = 2
  UsbdPipeTypeInterrupt    = 3
end enum
type USBD_PIPE_TYPE as _USBD_PIPE_TYPE

type _WINUSB_PIPE_INFORMATION
  as USBD_PIPE_TYPE PipeType
  as UCHAR          PipeId
  as USHORT         MaximumPacketSize
  as UCHAR          Interval
end type
type  WINUSB_PIPE_INFORMATION as _WINUSB_PIPE_INFORMATION
type PWINUSB_PIPE_INFORMATION as _WINUSB_PIPE_INFORMATION ptr

type _USB_CONFIGURATION_DESCRIPTOR
  as UCHAR  bLength
  as UCHAR  bDescriptorType
  as USHORT wTotalLength
  as UCHAR  bNumInterfaces
  as UCHAR  bConfigurationValue
  as UCHAR  iConfiguration
  as UCHAR  bmAttributes
  as UCHAR  MaxPower
end type
type  USB_CONFIGURATION_DESCRIPTOR as _USB_CONFIGURATION_DESCRIPTOR
type PUSB_CONFIGURATION_DESCRIPTOR as _USB_CONFIGURATION_DESCRIPTOR ptr

type _USB_COMMON_DESCRIPTOR
  as UCHAR bLength
  as UCHAR bDescriptorType
end type
type  USB_COMMON_DESCRIPTOR as _USB_COMMON_DESCRIPTOR
type PUSB_COMMON_DESCRIPTOR as _USB_COMMON_DESCRIPTOR ptr

extern "Windows-MS" lib "winusb"

declare function WinUsb_Initialize( _
  DeviceHandle    as HANDLE,                  _ ' IN
  InterfaceHandle as PWINUSB_INTERFACE_HANDLE _ ' OUT
  ) as BOOL

declare function WinUsb_Free( _
  InterfaceHandle as WINUSB_INTERFACE_HANDLE _ ' IN
  ) as BOOL


declare function WinUsb_GetAssociatedInterface( _
  InterfaceHandle           as WINUSB_INTERFACE_HANDLE , _ ' IN
  AssociatedInterfaceIndex  as UCHAR                   , _ ' IN
  AssociatedInterfaceHandle as PWINUSB_INTERFACE_HANDLE  _ ' OUT
  ) as BOOL

declare function WinUsb_GetDescriptor( _
  InterfaceHandle   as WINUSB_INTERFACE_HANDLE, _ ' IN
  DescriptorType    as UCHAR                  , _ ' IN
  Index             as UCHAR                  , _ ' IN
  LanguageID        as USHORT                 , _ ' IN
  Buffer            as PUCHAR                 , _ ' OUT
  BufferLength      as ULONG                  , _ ' IN
  LengthTransferred as PULONG                   _ ' OUT
  ) as BOOL

declare function WinUsb_QueryInterfaceSettings( _
  InterfaceHandle           as WINUSB_INTERFACE_HANDLE , _ ' IN
  AlternateInterfaceNumber  as UCHAR                   , _ ' IN
  UsbAltInterfaceDescriptor as PUSB_INTERFACE_DESCRIPTOR _ ' OUT
  ) as BOOL

declare function WinUsb_QueryDeviceInformation( _
  InterfaceHandle as WINUSB_INTERFACE_HANDLE, _ ' IN
  InformationType as ULONG                  , _ ' IN
  BufferLength    as PULONG                 , _ ' IN OUT
  Buffer          as PVOID                    _ ' OUT
  ) as BOOL

declare function WinUsb_SetCurrentAlternateSetting( _
  InterfaceHandle as WINUSB_INTERFACE_HANDLE, _ ' IN
  SettingNumber   as UCHAR                    _ ' IN
  ) as BOOL

declare function WinUsb_GetCurrentAlternateSetting( _
  InterfaceHandle as WINUSB_INTERFACE_HANDLE, _ ' IN
  SettingNumber   as PUCHAR                   _ ' OUT
  ) as BOOL

declare function WinUsb_QueryPipe( _
  InterfaceHandle          as WINUSB_INTERFACE_HANDLE, _ ' IN
  AlternateInterfaceNumber as UCHAR                  , _ ' IN
  PipeIndex                as UCHAR                  , _ ' IN
  PipeInformation          as PWINUSB_PIPE_INFORMATION _  ' OUT
  ) as BOOL

declare function WinUsb_SetPipePolicy( _
  InterfaceHandle as WINUSB_INTERFACE_HANDLE, _ ' IN
  PipeID          as UCHAR                  , _ ' IN
  PolicyType      as ULONG                  , _ ' IN
  ValueLength     as ULONG                  , _ ' IN
  Value           as PVOID                    _ ' IN
  ) as BOOL

declare function WinUsb_GetPipePolicy( _
  InterfaceHandle as WINUSB_INTERFACE_HANDLE, _ ' IN
  PipeID          as UCHAR                  , _ ' IN
  PolicyType      as ULONG                  , _ ' IN
  ValueLength     as PULONG                 , _ ' IN OUT
  Value           as PVOID                    _ ' OUT
  ) as BOOL

declare function WinUsb_ReadPipe( _
  InterfaceHandle   as WINUSB_INTERFACE_HANDLE, _ ' IN
  PipeID            as UCHAR                  , _ ' IN
  Buffer            as PUCHAR                 , _ ' IN
  BufferLength      as ULONG                  , _ ' IN
  LengthTransferred as PULONG                 , _ ' OUT
  Overlapped        as LPOVERLAPPED             _ ' IN
  ) as BOOL

declare function WinUsb_WritePipe( _
  InterfaceHandle   as WINUSB_INTERFACE_HANDLE, _ ' IN
  PipeID            as UCHAR                  , _ ' IN
  Buffer            as PUCHAR                 , _ ' IN
  BufferLength      as ULONG                  , _ ' IN
  LengthTransferred as PULONG                 , _ ' OUT
  Overlapped        as LPOVERLAPPED             _ ' IN
  ) as BOOL

declare function WinUsb_ControlTransfer( _
  InterfaceHandle   as WINUSB_INTERFACE_HANDLE, _ ' IN
  SetupPacket       as WINUSB_SETUP_PACKET    , _ ' IN
  Buffer            as PUCHAR                 , _ ' IN
  BufferLength      as ULONG                  , _ ' IN
  LengthTransferred as PULONG                 , _ ' OUT
  Overlapped        as LPOVERLAPPED             _ ' IN
  ) as BOOL

declare function WinUsb_ResetPipe( _
  InterfaceHandle as WINUSB_INTERFACE_HANDLE, _ ' IN
  PipeID          as UCHAR                    _ ' IN
  ) as BOOL

declare function WinUsb_AbortPipe( _
  InterfaceHandle as WINUSB_INTERFACE_HANDLE, _ ' IN
  PipeID          as UCHAR                    _ ' IN
  ) as BOOL

declare function WinUsb_FlushPipe( _
  InterfaceHandle as WINUSB_INTERFACE_HANDLE, _ ' IN
  PipeID          as UCHAR                    _ ' IN
  ) as BOOL

declare function WinUsb_SetPowerPolicy( _
  InterfaceHandle as WINUSB_INTERFACE_HANDLE, _ ' IN
  PolicyType      as ULONG                  , _ ' IN
  ValueLength     as ULONG                  , _ ' IN
  Value           as PVOID _                    ' IN
  ) as BOOL

declare function WinUsb_GetPowerPolicy( _
  InterfaceHandle as WINUSB_INTERFACE_HANDLE, _ ' IN
  PolicyType      as ULONG                  , _ ' IN
  ValueLength     as PULONG                 , _ ' IN OUT
  Value           as PVOID                    _ ' OUT
  ) as BOOL

declare function WinUsb_GetOverlappedResult( _
  InterfaceHandle            as WINUSB_INTERFACE_HANDLE, _ ' IN
  lpOverlapped               as LPOVERLAPPED           , _ ' IN
  lpNumberOfBytesTransferred as LPDWORD                , _ ' OUT
  bWait as BOOL) as BOOL

declare function WinUsb_ParseConfigurationDescriptor( _
  ConfigurationDescriptor as PUSB_CONFIGURATION_DESCRIPTOR, _ ' IN
  StartPosition           as PVOID                        , _ ' IN
  InterfaceNumber         as LONG                         , _ ' IN
  AlternateSetting        as LONG                         , _ ' IN
  InterfaceClass          as LONG                         , _ ' IN
  InterfaceSubClass       as LONG                         , _ ' IN
  InterfaceProtocol       as LONG                           _ ' IN
  ) as PUSB_INTERFACE_DESCRIPTOR

declare function WinUsb_ParseDescriptors( _
  DescriptorBuffer as PVOID    , _ ' IN
  TotalLength      as ULONG    , _ ' IN
  StartPosition    as PVOID    , _ ' IN
  DescriptorType   as LONG       _ ' IN
  ) as PUSB_COMMON_DESCRIPTOR

end extern

#endif ' __WINUSB_BI__
larchi
Posts: 3
Joined: Jan 20, 2012 17:16

Re: WINUSB.bi

Post by larchi »

hello DJ Peters
First of all congratulations for your participation in improving FreeBasic. it's amazing!
I need you because I will want to use Winusb.bi to test the presence and operation of proprietary drivers (camera ...)
Can you send us an example of use in FB?
thanks in advance
Cheers
Post Reply