Buchempfehlung
MySQL kurz & gut
MySQL kurz & gut
Das preiswerte Taschen- buch stellt MySQL-rele- vante Inhalte systematisch und knapp dar, sodass es sich optimal zum Nach- schlagen beim Pro- grammieren eignet. [Mehr Infos...]
FreeBASIC-Chat
Es sind Benutzer im FreeBASIC-Chat online.
(Stand:  )
FreeBASIC bei Twitter
Twitter FreeBASIC-Nachrichten jetzt auch über Twitter erhalten. Follow us!


Code-Beispiel

Code-Beispiele » Sonstiges

Auflisten USB HID-Geräte

Lizenz:Erster Autor:Letzte Bearbeitung:
GPLRedakteurVolta 10.04.2009

Auflistung der USB HID-Devices:
wie Maus, Tastatur, Gamepad, USBSoundcard ... sofern welche angeschlossen sind.
(Keine Speichersticks, da sie nicht als HID-Device angemeldet werden)

'HID_Guid.bas by Volta 10.04.2009
' for Human Interface Device Class,
' not for mass-storage-class devices
' read http://www.lvr.com/hidpage.htm

#Include Once "windows.bi"
#Include Once "win\setupapi.bi"
#Include Once "win\ocidl.bi"

Type HIDD_ATTRIBUTES
  size As Dword
  VendorID As Word
  ProductID As Word
  VersionNumber As Word
End Type
Dim As HIDD_ATTRIBUTES HIDAttributes

Type my_DEVICE_INTERFACE_DETAIL_DATA
  cbSize As Integer
  txt As ZString*160
End Type
Dim As my_DEVICE_INTERFACE_DETAIL_DATA SPDEVICEINTERFACEDETAILDATA

Dim HDEVINFO As hDevInfo
Dim As SP_DEVINFO_DATA  DeviceInfoData
Dim As SP_DEVICE_INTERFACE_DATA Spdeviceinterfacedata
Dim buffersize As Integer
Dim hPort As HANDLE
Dim As WString*128 WS

ScreenRes 640,480
Color ,1
Width 640\8, 480\14
Color 14, 1

Dim guid As GUID
Dim guids As LPOLESTR
Dim As Any Ptr hLib = DylibLoad( "hid.dll" )
Dim HidD_GetHidGuid As Sub(ByVal guidv As guid Ptr) _
= DyLibSymbol(hlib, "HidD_GetHidGuid")

Dim HidD_GetAttributes As _
Function(ByVal As HANDLE, ByVal As Any Ptr)As Integer _
= DyLibSymbol(hlib, "HidD_GetAttributes")

Dim HidD_GetManufacturerString As _
Function(ByVal As HANDLE, ByVal As Any Ptr, ByVal As Integer)As Integer _
= DyLibSymbol(hlib, "HidD_GetManufacturerString")

Dim HidD_GetProductString As _
Function(ByVal As HANDLE, ByVal As Any Ptr, ByVal As Integer)As Integer _
= DyLibSymbol(hlib, "HidD_GetProductString")

Dim HidD_GetSerialNumberString As _
Function(ByVal As HANDLE, ByVal As Any Ptr, ByVal As Integer)As Integer _
= DyLibSymbol(hlib, "HidD_GetSerialNumberString")

If hLib = 0 Then
  Print "Dylibload(hid.dll) failed"
  Sleep : End
Else
  HidD_GetHidGuid(@guid)
  StringFromIID(@guid,@guids)
  Print "USB_HID_GUID: ";*guids
End If


hDevInfo = SetupDiGetClassDevs(@guid,0,0,DIGCF_PRESENT Or DIGCF_DEVICEINTERFACE)
If hDevInfo = INVALID_HANDLE_VALUE Then
  Print "SetupDiGetClassDevs failed"
  Sleep : End
End If
Print

Dim MemberIndex As Integer
DeviceInfoData.cbSize = SizeOf(SP_DEVINFO_DATA)
If SetupDiEnumDeviceInfo(hDevInfo, MemberIndex, @DeviceInfoData) <> 0 Then
  StringFromIID(@DeviceInfoData. ClassGuid, @guids)
  Print "ClassGuid: " ; *guids

  Do
    Spdeviceinterfacedata.cbSize = SizeOf(SP_DEVICE_INTERFACE_DATA)
    If SetupDiEnumDeviceInterfaces(hDevInfo, 0, @guid, MemberIndex, _
    @SpDeviceInterfaceData) = 0 And GetLastError() = ERROR_NO_MORE_ITEMS _
    Then Exit Do
    StringFromIID(@Spdeviceinterfacedata.InterfaceClassGuid, @guids)
    Print "InterfaceClassGuid: " ; *guids


    buffersize=SizeOf(my_DEVICE_INTERFACE_DETAIL_DATA)'the size of the structure inc. NULL
    SPDEVICEINTERFACEDETAILDATA.cbSize = 5 'the size of the fixed part
    If SetupDiGetDeviceInterfaceDetail(hDevInfo, @Spdeviceinterfacedata, _
      Cast(Any Ptr, @SPDEVICEINTERFACEDETAILDATA), buffersize, 0, 0) = 0 Then

      If GetLastError() = ERROR_INSUFFICIENT_BUFFER Then Exit Do
    End If
    Print "DevicePathName: " ; SPDEVICEINTERFACEDETAILDATA.txt

    SetLastError(0)
    hPort = CreateFile(StrPtr(SPDEVICEINTERFACEDETAILDATA.txt), _
    GENERIC_READ Or GENERIC_WRITE, _
    FILE_SHARE_READ Or FILE_SHARE_WRITE, 0, OPEN_EXISTING, 0, 0)

    If hPort = 0 Then Exit Do
    If GetLastError() Then Exit Do

    HIDAttributes.size = SizeOf(HIDD_ATTRIBUTES)
    HidD_GetAttributes(hPort, @HIDAttributes)
    If GetLastError() Then Exit Do
    Print  "VendorID: " ; Hex(HIDAttributes.VendorID, 4) ; " ; " ;
    Print  "ProductID: " ; Hex(HIDAttributes.ProductID, 4) ; " ; " ;
    Print  "VersionNumber: " ; Hex(HIDAttributes.VersionNumber, 4)

    If HidD_GetManufacturerString(hPort,StrPtr(WS), 128) Then _
    Print "Manufacturer: " ; WS
    If HidD_GetProductString(hPort,StrPtr(WS), 128) Then _
    Print "Product:      " ; WS
    If HidD_GetSerialNumberString(hPort,StrPtr(WS), 128) Then _
    Print "SerialNumber: " ; WS

    MemberIndex = MemberIndex + 1

    Color ,4 : Print "[SPACE]"
    Sleep
    Locate LoWord(HiByte(Locate))-1
    Color ,1 : Print "       "
  Loop
  Color ,4 : Print "[END]"
End if

SetupDiDestroyDeviceInfoList(@hDevInfo)
If hPort Then CloseHandle(hPort)
If hLib Then DyLibFree hLib
Sleep

Attachments zum Code-Beispiel
QuelltextHIDGuid.basHIDGuid.BASRedakteurVolta10.04.09
QuelltextHID_Guid.basetwas verbessertRedakteurVolta10.04.09

Zusätzliche Informationen und Funktionen
  • Das Code-Beispiel wurde am 10.04.2009 von RedakteurVolta angelegt.
  • Die aktuellste Version wurde am 10.04.2009 von RedakteurVolta gespeichert.
  Bearbeiten Bearbeiten  

  Versionen Versionen