J
John Withers
I am having some trouble getting this working in VB.NET.
I have found numerous examples for VB 6, but nothing
on .NET so I am having to try to convert. I am making
baby steps in progress, but have not been able to get past
a certain point. I have not been able to convert by byte
array to a string. Also, if anyone knows a good reference
for VB .NET usb hardware i/o, let me know. I have not
been able to find anything on the internet or www.usb.org.
Dim DetailDataBuffer() as Byte
devInfo = SetupDiGetClassDevs(HidGuid, vbNullString, _
Me.Handle.ToInt32, _
DIGCF_PRESENT Or _
DIGCF_DEVICEINTERFACE)
' Size should be 28 bytes
DeviceInterfaceData.cbSize = 28
DeviceInfoData.cbSize = Len(DeviceInfoData.ToString)
result = SetupDiGetDeviceInterfaceDetail(devInfo, _
DeviceInterfaceData, _
0, _
0, _
Needed, _
0)
DetailDataSize = Needed
DeviceInterfaceDetailData.cbSize = 5
ReDim DetailDataBuffer(DetailDataSize)
' Store cbSize in the first byte of the buffer
RtlMoveMemory(DetailDataBuffer(0), _
DeviceInterfaceDetailData, 4)
' Call again, but pass first byte of detaildatabuffer
result = SetupDiGetDeviceInterfaceDetail(devInfo, _
DeviceInterfaceData, _
DetailDataBuffer, _
DetailDataSize, _
Needed, _
0)
' This should return my device path into DetailDataBuffer
' The convert to string
DevicePathName =
System.Text.UnicodeEncoding.Unicode.GetString
(DetailDataBuffer)
I have found numerous examples for VB 6, but nothing
on .NET so I am having to try to convert. I am making
baby steps in progress, but have not been able to get past
a certain point. I have not been able to convert by byte
array to a string. Also, if anyone knows a good reference
for VB .NET usb hardware i/o, let me know. I have not
been able to find anything on the internet or www.usb.org.
Dim DetailDataBuffer() as Byte
devInfo = SetupDiGetClassDevs(HidGuid, vbNullString, _
Me.Handle.ToInt32, _
DIGCF_PRESENT Or _
DIGCF_DEVICEINTERFACE)
' Size should be 28 bytes
DeviceInterfaceData.cbSize = 28
DeviceInfoData.cbSize = Len(DeviceInfoData.ToString)
result = SetupDiGetDeviceInterfaceDetail(devInfo, _
DeviceInterfaceData, _
0, _
0, _
Needed, _
0)
DetailDataSize = Needed
DeviceInterfaceDetailData.cbSize = 5
ReDim DetailDataBuffer(DetailDataSize)
' Store cbSize in the first byte of the buffer
RtlMoveMemory(DetailDataBuffer(0), _
DeviceInterfaceDetailData, 4)
' Call again, but pass first byte of detaildatabuffer
result = SetupDiGetDeviceInterfaceDetail(devInfo, _
DeviceInterfaceData, _
DetailDataBuffer, _
DetailDataSize, _
Needed, _
0)
' This should return my device path into DetailDataBuffer
' The convert to string
DevicePathName =
System.Text.UnicodeEncoding.Unicode.GetString
(DetailDataBuffer)