Help with InternetDial & InternetHangUp

A

Adrian

Hello, I'm currently converting a program at which needs to be able to
dial and disconnect a specified DUN entry.

The VB6 code is as follows and works fine, showing the dialog box for
username and password etc.:

Private Declare Function InternetHangUp Lib "wininet.dll" (ByVal
dwConnection As Long, ByVal dwReserved As Long) As Long
Private Declare Function InternetDial Lib "wininet.dll" (ByVal hWnd As
Long, ByVal sConnectoid As String, ByVal dwFlags As Long,
lpdwConnection As Long, ByVal dwReserved As Long) As Long
Dim ConnectionNumber As Long
Private Sub cmdDisconnect_Click()
lngresult = InternetHangUp(ConnectionNumber, 0)
End Sub
Private Sub Form_Load()
lngresult = InternetDial(0, "test", 0, ConnectionNumber, 0&)
End Sub

I cannot get it to work in VB.net though:

Public Declare Function InternetDial Lib "wininet.dll" (ByVal hWnd As
Long, ByVal sConnectoid As String, ByVal dwFlags As Long, ByVal
lpdwConnection As Long, ByVal dwReserved As Long) As Long

Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim lngresult As Long
Dim ConnectionNumber As Long

lngresult = InternetDial(0, "test", 0, ConnectionNumber, 0&)

There are no errors and the program 'runs' okay, but no dialog box
appears and the lngresult is 30064771159.

Hoping for help before my head explodes! :-(

Many thanks
Adrian
 
A

Armin Zingler

Adrian said:
Hello, I'm currently converting a program at which needs to be able
to dial and disconnect a specified DUN entry.

The VB6 code is as follows and works fine, showing the dialog box
for username and password etc.:

Private Declare Function InternetHangUp Lib "wininet.dll" (ByVal
dwConnection As Long, ByVal dwReserved As Long) As Long
Private Declare Function InternetDial Lib "wininet.dll" (ByVal hWnd
As Long, ByVal sConnectoid As String, ByVal dwFlags As Long,
lpdwConnection As Long, ByVal dwReserved As Long) As Long
Dim ConnectionNumber As Long
Private Sub cmdDisconnect_Click()
lngresult = InternetHangUp(ConnectionNumber, 0)
End Sub
Private Sub Form_Load()
lngresult = InternetDial(0, "test", 0, ConnectionNumber, 0&)
End Sub

I cannot get it to work in VB.net though:

Public Declare Function InternetDial Lib "wininet.dll" (ByVal hWnd
As Long, ByVal sConnectoid As String, ByVal dwFlags As Long, ByVal
lpdwConnection As Long, ByVal dwReserved As Long) As Long

Private Sub Form2_Load(ByVal sender As System.Object, ByVal e
As
System.EventArgs) Handles MyBase.Load
Dim lngresult As Long
Dim ConnectionNumber As Long

lngresult = InternetDial(0, "test", 0, ConnectionNumber,
0&)

There are no errors and the program 'runs' okay, but no dialog box
appears and the lngresult is 30064771159.

Hoping for help before my head explodes! :-(


http://msdn.microsoft.com/library/en-us/vblr7/html/vagrpDataType.asp

=> in VB.NET, replace Long by Integer. "hWnd" should be declared "As
IntPtr".
 
A

Adrian Wallis

http://msdn.microsoft.com/library/en-us/vblr7/html/vagrpDataType.asp

=> in VB.NET, replace Long by Integer. "hWnd" should be declared "As
IntPtr".

Thanks, I'd spotted that in a newsgroup and tried it...

Public Declare Function InternetDial Lib "wininet.dll" (ByVal hWnd As
IntPtr, ByVal sConnectoid As String, ByVal dwFlags As Long, ByVal
lpdwConnection As Long, ByVal dwReserved As Long) As Long
Private Sub Form2_Load(ByVal sender As System.Object, ByValue As
System.EventArgs) Handles MyBase.Load
Dim lngresult As Long
Dim ConnectionNumber As Long

lngresult = InternetDial(me.Handle, "test", 0, ConnectionNumber,
0&)

....but it made no difference - no dialog and the same meaningless error
code.

Adrian
 
T

Tom Shelton

Hello, I'm currently converting a program at which needs to be able to
dial and disconnect a specified DUN entry.

The VB6 code is as follows and works fine, showing the dialog box for
username and password etc.:

Private Declare Function InternetHangUp Lib "wininet.dll" (ByVal
dwConnection As Long, ByVal dwReserved As Long) As Long
Private Declare Function InternetDial Lib "wininet.dll" (ByVal hWnd As
Long, ByVal sConnectoid As String, ByVal dwFlags As Long,
lpdwConnection As Long, ByVal dwReserved As Long) As Long
Dim ConnectionNumber As Long
Private Sub cmdDisconnect_Click()
lngresult = InternetHangUp(ConnectionNumber, 0)
End Sub
Private Sub Form_Load()
lngresult = InternetDial(0, "test", 0, ConnectionNumber, 0&)
End Sub

I cannot get it to work in VB.net though:

Public Declare Function InternetDial Lib "wininet.dll" (ByVal hWnd As
Long, ByVal sConnectoid As String, ByVal dwFlags As Long, ByVal
lpdwConnection As Long, ByVal dwReserved As Long) As Long

Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim lngresult As Long
Dim ConnectionNumber As Long

lngresult = InternetDial(0, "test", 0, ConnectionNumber, 0&)

There are no errors and the program 'runs' okay, but no dialog box
appears and the lngresult is 30064771159.

Hoping for help before my head explodes! :-(

Many thanks
Adrian

This seems to work:

Private Declare Auto Function InternetDial Lib "wininet" _
(ByVal hwndParent As IntPtr, _
ByVal lpszConnection As String, _
ByVal dwFlags As Integer, _
ByRef lpdwConnection As Integer, _
ByVal dwReserved As Integer) As Integer

HTH
 
A

Armin Zingler

Adrian Wallis said:
Thanks, I'd spotted that in a newsgroup and tried it...

Public Declare Function InternetDial Lib "wininet.dll" (ByVal hWnd
As IntPtr, ByVal sConnectoid As String, ByVal dwFlags As Long,
ByVal lpdwConnection As Long, ByVal dwReserved As Long) As Long
Private Sub Form2_Load(ByVal sender As System.Object, ByValue As
System.EventArgs) Handles MyBase.Load
Dim lngresult As Long
Dim ConnectionNumber As Long

lngresult = InternetDial(me.Handle, "test", 0,
ConnectionNumber,
0&)

...but it made no difference - no dialog and the same meaningless
error code.

As I wrote, you should replace Long by Integer - but let me do this for you:

Public Declare Function InternetDial Lib "wininet.dll" ( _
ByVal hWnd As IntPtr, ByVal sConnectoid As String, ByVal dwFlags As
Integer, _
ByRef lpdwConnection As Integer, ByVal dwReserved As Integer) As Integer



I also replaced "ByRef lpdwConnection As Integer" to "Byval ..." because the
C declaration is "LPDWORD".
 

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