Controlling Dial Up Networking using the WinInet API

Page 3 of 3
  1. Introduction
  2. Are we connected?
  3. Connecting & Disconnecting

Connecting & Disconnecting

So now how do you connect to the ISP of the EU if they are not connected to do your things? Easy just go back to your oh faithful WinInet API.

Private Declare Function InternetOpen Lib "wininet.dll" Alias "InternetOpenA" (ByVal sAgent As String, ByVal lAccessType As Long, ByVal sProxyName As String, ByVal sProxyBypass As String, ByVal lFlags As Long) As Long
Private Declare Function InternetAttemptConnect Lib "WinInet" (ByVal dwReserved As Long) As Long
Const scUserAgent = "WinInet Example"
Const INTERNET_OPEN_TYPE_PRECONFIG = 0
Public Function ConnectToISP() As Boolean
   If InternetAttemptConnect(0) <> 0 Then Exit Function
   If InternetOpen(scUserAgent, INTERNET_OPEN_TYPE_PRECONFIG, vbNullString, vbNullString, 0) = 0 Then ConnectToISP = False Else ConnectToISP = True
End Function

How about hanging Up the darn modem? Yep you guessed it... back to the WinInet API.

Private Declare Function InternetAutodialHangup Lib "wininet.dll" (ByVal dwReserved_ As Long) As Long
Public Function HangUpModem() As Boolean
    If InternetAutodialHangup(0&) = 0 Then HangUpModem = False Else HangUpModem = True
End Function

There! Three functions you'll need if you are wanting to make an internet related application which may require you to connect/disconnect and check the status of hte connection to continue.

Remember to use the Windows API as much as possible when checking for stuff related to the system. Not only is it faster but its most likely easier for you as the developer to use the API function than searching Registry Keys or other things. Next time around I'll show you how to get some information about the Dialup Networking Connection. I've attached a VB6 project so you can add that module to your projects. If your a VB5 user open the .VBP file in Notepad and remove the 'Retained' key.

You might also like...

Comments

About the author

Thushan Fernando

Thushan Fernando Australia

Senior Developer working at Readify on cool new technology and platforms.

Interested in writing for us? Find out more.

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“UNIX is basically a simple operating system, but you have to be a genius to understand the simplicity.” - Dennis Ritchie