Interesting problem!

S

Steve

Hi all,

I am having difficulty getting information from the system on USB devices
attached. The following is a snippet of the code:

Function declarations

Public Declare Function SetupDiGetClassDevs Lib "setupapi.dll" _
Alias "SetupDiGetClassDevsA" ( _
ByRef ClassGuid As Guid, _
ByVal Enumerator As String, _
ByVal hwndParent As Long, _
ByVal flags As Long) As Long

Public Declare Function SetupDiEnumDeviceInfo Lib "setupapi.dll" ( _
ByVal DeviceInfoSet As Long, _
ByVal MemberIndex As Long, _
ByRef DeviceInfoData As SP_DEVINFO_DATA) As Long


Part of the code:

Dim GUID_DEV_USB As Guid
Dim DevInfo As SP_DEVINFO_DATA

ReDim GUID_DEV_USB.data4(7)

With GUID_DEV_USB ' USB GUID
.Data1 = &HA5DCBF10
.Data2 = &H6530
.Data3 = &H11D2
.data4(0) = &H90
.data4(1) = &H1F
.data4(2) = &H0
.data4(3) = &HC0
.data4(4) = &H4F
.data4(5) = &HB9
.data4(6) = &H51
.data4(7) = &HED
End With

' Get device list
hDevInfo = SetupDiGetClassDevs(GUID_DEVCLASS_USB, vbNullString, vbNull,
DIGCF_PRESENT Or DIGCF_DEVICEINTERFACE)

DevInfo.cbSize = Len(DevInfo)

' Enumerate the devices attached
SetupDiEnumDeviceInfo(hDevInfo, I, DevInfo)

this snippet is part of a loop, I starts at 0

Here is the problem. hDevInfo returns an error. Well, not an error as
such, but a handle with the value of 9222812402617788072 (!).

The above code works in C, so why not VB .NET??

Many thanks,

Steve.
 
H

Herfried K. Wagner [MVP]

Steve said:
I am having difficulty getting information from the system on USB devices
attached. The following is a snippet of the code:

Function declarations

Public Declare Function SetupDiGetClassDevs Lib "setupapi.dll" _
Alias "SetupDiGetClassDevsA" ( _

Skip the alias and use 'Declare Auto Function' instead.
ByRef ClassGuid As Guid, _

Use Win32' 'GUID' structure here.
ByVal hwndParent As Long, _

=> 'As IntPtr'.
ByVal flags As Long

=> 'As Int32'.

) As Long

=> 'As IntPtr'.
Public Declare Function SetupDiEnumDeviceInfo Lib "setupapi.dll" ( _
ByVal DeviceInfoSet As Long, _

=> 'As IntPtr'.
ByVal MemberIndex As Long, _

=> 'As Int32'.
) As Long

=> 'As Boolean'.
The above code works in C, so why not VB .NET??

See above.
 
S

Steve

Many thanks for that Herfried, but the code still does not produce the
expected results.
With your changes, I now get what I consider a valid handle to a device
list. However, SetupDiEnumDeviceInfo always returns false and the error
code returned is ERROR_NO_MORE_ITEMS, even on the first call even though I
have 2 USB devices connected!

Any thoughts please?

Thanks again for your valuable help so far.

Steve.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top