Code-Beispiel
Auflisten USB HID-Geräte
Lizenz: | Erster Autor: | Letzte Bearbeitung: |
GPL | Volta | 24.04.2015 |
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 23.04.2015
' for Human Interface Device (HID) Class,
' not for mass-storage-class devices
#Include Once "windows.bi"
#Include Once "win\setupapi.bi"
#Include Once "win\ocidl.bi"
#Inclib "libhid"
Declare Sub HidD_GetHidGuid Alias "HidD_GetHidGuid" (As LPGUID )
Declare Function HidD_GetAttributes Alias "HidD_GetAttributes" (As HANDLE, As Any Ptr)As Long
Declare Function HidD_GetManufacturerString Alias "HidD_GetManufacturerString" ( As HANDLE, As Any Ptr, As long)As Long
Declare Function HidD_GetProductString Alias "HidD_GetProductString" ( As HANDLE, As Any Ptr, As long)As Long
Declare Function HidD_GetSerialNumberString Alias "HidD_GetSerialNumberString" ( As HANDLE, As Any Ptr, As long)As Long
Type HIDD_ATTRIBUTES
size As Dword
VendorID As Word
ProductID As Word
VersionNumber As Word
End Type
Dim As HIDD_ATTRIBUTES HIDAttributes
Type DEVICE_INTERFACE_DETAIL_DATA
cbSize As Long
txt As ZString*250
End Type
Dim As 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 long
Dim hPort As HANDLE
Dim As WString*250 WS
ScreenRes 480,480
Color ,1
Width 480\8, 480\14
Color 14, 1
Dim guid As GUID
Dim guids As LPOLESTR
Dim As UByte buf(64)
HidD_GetHidGuid(@guid)
StringFromIID(@guid,@guids)
Print
Print "USB_HID_GUID: ";*guids
hDevInfo = SetupDiGetClassDevs(@guid,0,0,DIGCF_PRESENT Or DIGCF_DEVICEINTERFACE)
If hDevInfo = INVALID_HANDLE_VALUE Then
Print "SetupDiGetClassDevs failed"
Sleep : End
End If
Dim As long MemberIndex=1
DeviceInfoData.cbSize = SizeOf(SP_DEVINFO_DATA)
If SetupDiEnumDeviceInfo(hDevInfo, MemberIndex, @DeviceInfoData) <> 0 Then
StringFromIID(@DeviceInfoData. ClassGuid, @guids)
Print "ClassGuid: " ; *guids
Print
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(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), 0, _
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 200,1
Locate LoWord(HiByte(Locate))-1
Color ,1 : Print " "
If hPort Then CloseHandle(hPort)
Loop
Color ,4 : Print "[END]"
End If
SetupDiDestroyDeviceInfoList(@hDevInfo)
If hPort Then CloseHandle(hPort)
Sleep
Attachments zum Code-Beispiel | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
Zusätzliche Informationen und Funktionen | |||||||
---|---|---|---|---|---|---|---|
|