The following is some code that I am trying to bring over from VB 6.0, that I have working there. I am trying to get to where I can talk to a USB device. I am stuck on how to correctly pass params to the API call SetupDiGetDeviceInterfaceDetail() I can get it to actully not fail, and it actully tells me that it returned 87 bytes which is correct, but it never fills my structure of DeviceInterfaceDetail, and of course return value is a failure because of it. I am sure that it is in how I am trying to pass the structure, but have tried several ways, but obviously don't know how to do it correctly. I have tried to use marshalby, but have never used it before, and probably not doing it correct. Can anyone help? I have only worked on getting code working up to this routine, so I know that the definitions for some of the other calls need to be fixed, but if you look at the code that Iincluded, those calls I think are correct, so if those definitions need fixed, let me know
**************** My Definition
Public cnCurrentDb As OleDbConnectio
Public dsCurrentDB As DataSe
Public ArryData(10, 4) As Objec
Public adProgData As OleDbDataAdapte
Public adProgName As OleDbDataAdapte
Public adRunActuals As OleDbDataAdapte
Public adRunInfo As OleDbDataAdapte
Public adProgSteps As OleDbDataAdapte
Public strSql As Strin
Public strDbName As Strin
Public FormReturn As Int1
Public HidHandle As Lon
Public OurDevHndl As Lon
Public Const HEADER_NAME = "WinCryo by Gordinier Electronics
Public Const MAX_TEMP = 4
Public Const MIN_TEMP = -20
Public Const MAX_RATE = 3
Public HidGuid As Gui
Public Structure Device_Interface_Dat
Dim cbsize As Int3
Dim InterfaceClassGuid As Gui
Dim Flags As Int3
Dim ReservedPtr As Intege
End Structur
<StructLayout(LayoutKind.Sequential)> Public Structure Device_Interface_Detai
Public cbsize As Intege
<MarshalAs(UnmanagedType.ByValArray, sizeconst:=256)> Public DataPath() As Byt
''UPGRADE_TODO: "Initialize" must be called to initialize instances of this structure. Click for more: 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1026"
Public Sub Initialize(
ReDim DataPath(255
End Su
End Structur
Public Structure Security_Attribute
Public nLength As Intege
Public lpSecurityDescriptor As Intege
Public bInheritHandle As Intege
End Structur
Public Structure HidD_Attribute
Public Size As Lon
Public VendorID As Shor
Public ProductID As Shor
Public VersionNumber As Shor
End Structur
Public Structure SP_DEVINFO_DAT
Public cbsize As Intege
Public ClassGuid As Gui
Public DevInst As Intege
Public Reserved As Intege
End Structur
Public Class Win3
Declare Sub HidD_GetHidGuid Lib "HID.dll" (ByRef GuidPtr As Guid
Declare Auto Function SetupDiGetClassDevs Lib "setupapi.dll" Alias "SetupDiGetClassDevsA"
(ByRef GuidPtr As Guid,
ByRef EnumPtr As Integer,
ByRef HwndParent As Integer,
ByVal Flags As Integer)
As Intege
Declare Auto Function SetupDiEnumDeviceInterfaces Lib "setupapi.dll"
(ByVal Handle As Integer,
ByVal InfoPtr As Integer,
ByRef GuidPtr As Guid,
ByVal MemberIndex As Integer,
ByRef InterfaceDataPtr As Device_Interface_Data)
As Boolea
Declare Auto Function SetupDiGetDeviceInterfaceDetail Lib "setupapi.dll" Alias "SetupDiGetDeviceInterfaceDetailA"
(ByVal Handle As Integer,
ByRef InterfaceData As Device_Interface_Data,
ByVal InterfaceDetail As Device_Interface_Detail,
ByVal DetailLength As Integer,
ByRef ReturnedLength As Integer,
ByVal DevInfoData As Integer)
As Boolea
Declare Auto Function CreateFile Lib "kernel32" Alias "CreateFileA"
(ByRef lpFileName As String, _
ByVal dwDesiredAccess As Integer, _
ByVal dwShareMode As Integer, _
ByVal lpSecurityAttributes As Security_Attributes, _
ByVal dwCreationDisposition As Integer, _
ByVal dwFlagsAndAttributes As Integer, _
ByVal hTemplateFile As Integer) _
As Integer
'UPGRADE_WARNING: Structure Security_Attributes may require marshalling attributes to be passed as an argument in this Declare statement. Click for more: 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1050"'
Declare Function HidD_GetAttributes Lib "HID.dll" (ByVal Handle As Integer, ByRef BufferPtr As Integer) As Integer
Declare Sub CloseHandle Lib "kernel32" (ByVal HandleToClose As Integer)
Declare Function SetupDiDestroyDeviceInfoList Lib "setupapi.dll" (ByVal DeviceInfoSet As Integer) As Boolean
Declare Function GetLastError Lib "kernel32" () As Integer
Declare Function FormatMessage Lib "kernel32" (ByVal dwFlags As Int32, ByVal lpSource As Int32, ByVal dwMessageId As Int32, _
ByVal lpBuffer As Int32, ByVal nSize As Int32, ByVal arguments As Long) As Integer
End Class
Dim DeviceInterfaceData As Device_Interface_Data
************** MY CODE
Function OpenUSB() As Boolean
Dim PnPHandle As Int64
Dim HIDdevice As Long
Dim BytesReturned As Long
Dim inx As Int16
Dim HidName As String
Dim ThisHIDdevice As HidD_Attributes
Dim TempInt As Integer
Dim result As Boolean
Dim strTemp As String
Dim errNum As Int32
Dim ArrySize As Integer
Dim DeviceInterfaceData As Device_Interface_Data
Dim DeviceInterfaceDetail As Device_Interface_Detail
Dim DeviceInfoData As SP_DEVINFO_DATA
On Error GoTo OpenUSBErrHndlr
OpenUSB = True
' First, get my class identifier
Call Win32.HidD_GetHidGuid(HidGuid)
'strTemp = HidGuid.ToString
'
' Get a handle for the Plug and Play node and request currently active HID devices
PnPHandle = Win32.SetupDiGetClassDevs(HidGuid, 0, 0, &H12)
'If (PnPHandle& = -1) Then ErrorExit ("Could not attach to PnP node")
DeviceInterfaceData.cbsize = 28 'Length of data structure in bytes
'
' Lets look for a maximum of 20 HID devices
For HIDdevice = 0 To 19
' Is there a HID device at this table entry
DeviceInterfaceDetail.Initialize()
DeviceInterfaceDetail.cbsize = 5
If Win32.SetupDiEnumDeviceInterfaces(PnPHandle, 0, HidGuid, HIDdevice, DeviceInterfaceData) Then
' There is a device here, get it's name
result = Win32.SetupDiGetDeviceInterfaceDetail(PnPHandle, DeviceInterfaceData, DeviceInterfaceDetail, _
DeviceInterfaceDetail.cbsize, BytesReturned, 0)
********* This last call is where I am having trouble ******************