By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,163 Members | 1,284 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,163 IT Pros & Developers. It's quick & easy.

vb6 to vb.net help...

P: n/a
hi, i have been trying to convert the following codes to vb.net for 2 weeks,
and it still do not work while the old vb6 codes work perfectly fine...i
really do not know what wrongs with it... here the vb6 codes...
Sub ChangeConnection()
Dim DeviceInfoSet As Long
Dim GuidPtr As GUID
Dim InterfaceDataPtr As Device_Interface_Data
Dim InterfaceDetailDataPtr As Device_Interface_Detail
Dim InterfaceDetailDataSize As Long

Dim DeviceCancel As Boolean
Dim DeviceFound As Long
Dim RetVal As Long
Dim i, x, y, z As Integer
Dim tmpString As String
Dim NumUSB As Integer

'show correct frame for printer selection information
For x = 0 To 2
If ConnectionType = x Then
FrameConnection(x).Visible = True
FrameConnection(x).Enabled = True
Else
FrameConnection(x).Visible = False
FrameConnection(x).Enabled = False
End If
Next x

'other setup stuff
frmMain.Caption = "QPrint"
If ConnectionType = TCPIP Then
mnuGetReturnData.Enabled = False
Else
mnuGetReturnData.Enabled = True
End If

'USB find devices
If ConnectionType = USB Then
NumUSB = 0
For x = 0 To 7
txtSerial(x).Text = ""
Next x
'test 3 GUIDs
For z = 1 To 3
If z = 1 Then
'HP800 GUID2k
GuidPtr.Data1 = 2106991576
GuidPtr.Data2 = -27832
GuidPtr.Data3 = 4561
GuidPtr.Data4(0) = 134
GuidPtr.Data4(1) = 37
GuidPtr.Data4(2) = 8
GuidPtr.Data4(3) = 0
GuidPtr.Data4(4) = 9
GuidPtr.Data4(5) = 221
GuidPtr.Data4(6) = 147
GuidPtr.Data4(7) = 92
ElseIf z = 2 Then
'HP900 GUID2k
GuidPtr.Data1 = 685215661
GuidPtr.Data2 = 23058
GuidPtr.Data3 = 4561
GuidPtr.Data4(0) = 174
GuidPtr.Data4(1) = 91
GuidPtr.Data4(2) = 0
GuidPtr.Data4(3) = 0
GuidPtr.Data4(4) = 248
GuidPtr.Data4(5) = 3
GuidPtr.Data4(6) = 168
GuidPtr.Data4(7) = 194
ElseIf z = 3 Then
'HP900 Test GUID
GuidPtr.Data1 = 8863711
GuidPtr.Data2 = 25000
GuidPtr.Data3 = 4561
GuidPtr.Data4(0) = 170
GuidPtr.Data4(1) = 94
GuidPtr.Data4(2) = 0
GuidPtr.Data4(3) = 192
GuidPtr.Data4(4) = 79
GuidPtr.Data4(5) = 177
GuidPtr.Data4(6) = 114
GuidPtr.Data4(7) = 139
End If
InterfaceDataPtr.cbsize = 28
InterfaceDetailDataPtr.cbsize = 5

'get usb device handle for HP printers
DeviceInfoSet = SetupDiGetClassDevs(GuidPtr, 0&, 0&, DIGCF_PRESENT
Or DIGCF_INTERFACEDEVICE)
DeviceCancel = False
Do
'get interface pointer
DeviceFound = SetupDiEnumDeviceInterfaces(DeviceInfoSet, 0&,
GuidPtr, NumUSB, InterfaceDataPtr)
'device found
If DeviceFound = 1 Then
'get detail data size
InterfaceDetailDataSize = 0
RetVal = SetupDiGetDeviceInterfaceDetail(DeviceInfoSet,
InterfaceDataPtr, 0&, 0, InterfaceDetailDataSize, 0&)
RetVal = SetupDiGetDeviceInterfaceDetail2(DeviceInfoSet,
InterfaceDataPtr, InterfaceDetailDataPtr, InterfaceDetailDataSize, 0&, 0&)
'create serial # for name & get full device id
x = -1
y = 0
tmpString = ""
USBDeviceID(NumUSB) = ""
Do
x = x + 1
USBDeviceID(NumUSB) = USBDeviceID(NumUSB) &
Chr(InterfaceDetailDataPtr.DataPath(x))
If InterfaceDetailDataPtr.DataPath(x) = 35 Then y = y + 1
'found serial #
If y = 2 And InterfaceDetailDataPtr.DataPath(x) <> 35 Then
tmpString = tmpString &
Chr(InterfaceDetailDataPtr.DataPath(x))
End If
Loop Until InterfaceDetailDataPtr.DataPath(x) = 0
If NumUSB < 8 Then txtSerial(NumUSB).Text = tmpString
NumUSB = NumUSB + 1
Else
DeviceCancel = True
End If
Loop Until DeviceCancel = True
Next z

RetVal = SetupDiDestroyDeviceInfoList(DeviceInfoSet)
End If
End Sub
Nov 21 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On 2005-03-24, notregister <no*********@discussions.microsoft.com> wrote:
hi, i have been trying to convert the following codes to vb.net for 2 weeks,
and it still do not work while the old vb6 codes work perfectly fine...i
really do not know what wrongs with it... here the vb6 codes...
Sub ChangeConnection()
Dim DeviceInfoSet As Long
Dim GuidPtr As GUID
Dim InterfaceDataPtr As Device_Interface_Data
Dim InterfaceDetailDataPtr As Device_Interface_Detail
Dim InterfaceDetailDataSize As Long

Dim DeviceCancel As Boolean
Dim DeviceFound As Long
Dim RetVal As Long
Dim i, x, y, z As Integer
Dim tmpString As String
Dim NumUSB As Integer

'show correct frame for printer selection information
For x = 0 To 2
If ConnectionType = x Then
FrameConnection(x).Visible = True
FrameConnection(x).Enabled = True
Else
FrameConnection(x).Visible = False
FrameConnection(x).Enabled = False
End If
Next x

'other setup stuff
frmMain.Caption = "QPrint"
If ConnectionType = TCPIP Then
mnuGetReturnData.Enabled = False
Else
mnuGetReturnData.Enabled = True
End If

'USB find devices
If ConnectionType = USB Then
NumUSB = 0
For x = 0 To 7
txtSerial(x).Text = ""
Next x
'test 3 GUIDs
For z = 1 To 3
If z = 1 Then
'HP800 GUID2k
GuidPtr.Data1 = 2106991576
GuidPtr.Data2 = -27832
GuidPtr.Data3 = 4561
GuidPtr.Data4(0) = 134
GuidPtr.Data4(1) = 37
GuidPtr.Data4(2) = 8
GuidPtr.Data4(3) = 0
GuidPtr.Data4(4) = 9
GuidPtr.Data4(5) = 221
GuidPtr.Data4(6) = 147
GuidPtr.Data4(7) = 92
ElseIf z = 2 Then
'HP900 GUID2k
GuidPtr.Data1 = 685215661
GuidPtr.Data2 = 23058
GuidPtr.Data3 = 4561
GuidPtr.Data4(0) = 174
GuidPtr.Data4(1) = 91
GuidPtr.Data4(2) = 0
GuidPtr.Data4(3) = 0
GuidPtr.Data4(4) = 248
GuidPtr.Data4(5) = 3
GuidPtr.Data4(6) = 168
GuidPtr.Data4(7) = 194
ElseIf z = 3 Then
'HP900 Test GUID
GuidPtr.Data1 = 8863711
GuidPtr.Data2 = 25000
GuidPtr.Data3 = 4561
GuidPtr.Data4(0) = 170
GuidPtr.Data4(1) = 94
GuidPtr.Data4(2) = 0
GuidPtr.Data4(3) = 192
GuidPtr.Data4(4) = 79
GuidPtr.Data4(5) = 177
GuidPtr.Data4(6) = 114
GuidPtr.Data4(7) = 139
End If
InterfaceDataPtr.cbsize = 28
InterfaceDetailDataPtr.cbsize = 5

'get usb device handle for HP printers
DeviceInfoSet = SetupDiGetClassDevs(GuidPtr, 0&, 0&, DIGCF_PRESENT
Or DIGCF_INTERFACEDEVICE)
DeviceCancel = False
Do
'get interface pointer
DeviceFound = SetupDiEnumDeviceInterfaces(DeviceInfoSet, 0&,
GuidPtr, NumUSB, InterfaceDataPtr)
'device found
If DeviceFound = 1 Then
'get detail data size
InterfaceDetailDataSize = 0
RetVal = SetupDiGetDeviceInterfaceDetail(DeviceInfoSet,
InterfaceDataPtr, 0&, 0, InterfaceDetailDataSize, 0&)
RetVal = SetupDiGetDeviceInterfaceDetail2(DeviceInfoSet,
InterfaceDataPtr, InterfaceDetailDataPtr, InterfaceDetailDataSize, 0&, 0&)
'create serial # for name & get full device id
x = -1
y = 0
tmpString = ""
USBDeviceID(NumUSB) = ""
Do
x = x + 1
USBDeviceID(NumUSB) = USBDeviceID(NumUSB) &
Chr(InterfaceDetailDataPtr.DataPath(x))
If InterfaceDetailDataPtr.DataPath(x) = 35 Then y = y + 1
'found serial #
If y = 2 And InterfaceDetailDataPtr.DataPath(x) <> 35 Then
tmpString = tmpString &
Chr(InterfaceDetailDataPtr.DataPath(x))
End If
Loop Until InterfaceDetailDataPtr.DataPath(x) = 0
If NumUSB < 8 Then txtSerial(NumUSB).Text = tmpString
NumUSB = NumUSB + 1
Else
DeviceCancel = True
End If
Loop Until DeviceCancel = True
Next z

RetVal = SetupDiDestroyDeviceInfoList(DeviceInfoSet)
End If
End Sub


Can you give all the VB6 api declarations as well? I could look them
up, but I would rather see what you had :)

--
Tom Shelton [MVP]
Nov 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.