An object-oriented programming language developed by Microsoft that can be used in .NET.
See one of the samples I had posted, like in this thread : How do I retreive a USB "Bus reported device description"
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I am using VB 2005 and need help getting the following code to compile. The code retrieves USB device info:
'<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode, Pack:=1)> _
' Structure SP_DEVICE_INTERFACE_DETAIL_DATA
' Public cbSize As Integer
' <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=260)> _
' Public DevicePath As String
' End Structure
Dim didd As SP_DEVICE_INTERFACE_DETAIL_DATA = New SP_DEVICE_INTERFACE_DETAIL_DATA()
If IntPtr.Size = 8 Then 'for 64-bit operating systems
didd.cbSize = 8
Else
didd.cbSize = 4 + Marshal.SystemDefaultCharSize 'for 32-bit systems
End If
'<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)> _
' Public Structure SP_DEVINFO_DATA
' Public cbSize As Integer
' Public ClassGuid As Guid
' Public DevInst As Integer
' Public Reserved As IntPtr
' End Structure
Dim da As SP_DEVINFO_DATA = New SP_DEVINFO_DATA()
da.cbSize = Marshal.SizeOf(da)
'<DllImport("Setupapi.dll", CharSet:=CharSet.Unicode, SetLastError:=True)> _
' Public Shared Function SetupDiGetDeviceInterfaceDetail(ByVal hDevInfo As IntPtr, ByRef deviceInterfaceData As SP_DEVICE_INTERFACE_DATA, ByVal deviceInterfaceDetailData As IntPtr, ByVal deviceInterfaceDetailDataSize As UInt32, <System.Runtime.InteropServices.Out()> ByRef requiredSize As UInt32, ByVal deviceInfoData As IntPtr) As Boolean
'End Function
bRet = SetupDiGetDeviceInterfaceDetail(hdevDisplayInfoSet, data, didd, dwBytes, dwBytes, da)
' COMPILE ERRORS:
' ddid - SP_DEVICE_INTERFACE_DETAIL_DATA cannot be converted to 'System.IntPtr'
' da - SP_DEVINFO_DATA cannot be converted to 'System.IntPtr'
The code give the above two errors. How can I modify the code to compile and run properly.
Thanks,
Ken
An object-oriented programming language developed by Microsoft that can be used in .NET.
See one of the samples I had posted, like in this thread : How do I retreive a USB "Bus reported device description"
If this code compiled before then I cannot answer as to why but doing a quick google on pinvoke.net reveals the import should look like this.
Public Declare Auto Function SetupDiGetDeviceInterfaceDetail Lib "setupapi.dll" ( _
ByVal DeviceInfoSet As IntPtr, _
ByRef DeviceInterfaceData As SP_DEVICE_INTERFACE_DATA, _
ByRef DeviceInterfaceDetailData As SP_DEVICE_INTERFACE_DETAIL_DATA, _
ByVal DeviceInterfaceDetailDataSize As UInteger, _
ByRef RequiredSize As UInteger, _
ByRef DeviceInfoData As SP_DEVINFO_DATA) As Boolean '
Then you are passing (by ref) the structure, not a pointer to the structure. Additionally you didn't provide us all the input that you were passing so you may need to make additional changes as well. I'm also not sure that the SP_DEVICE_INTERFACE_DETAIL_DATA structure is properly set for the charset or its size is correct. But I haven't tested this. You can refer to the earlier PInvoke.net link to see what should be working VB code for this API.