Controlling Dial Up Networking using the WinInet API

Are we connected?

So to solve that problem heres a cleaner clear cut API based function which will get the result done faster and more efficiently without alot of coding. Not only that its compact so you can easily add this to a module or do as I do and make it into a DLL.

Private Declare Function InternetGetConnectedStateEx Lib "wininet.dll" Alias "InternetGetConnectedStateExA" (lpdwFlags As Long, lpszConnectionName As Long, dwNameLen As Long, ByVal dwReserved As Long) As Long

Public Function Connected() As Boolean
   Dim lNameLen            As Long
   Dim lRetVal             As Long
   Dim lConnectionFlags    As Long
   Dim LPTR                As Long
   Dim lNameLenPtr         As Long
   Dim sConnectionName     As String
  sConnectionName = Space$(256)
   lNameLen = 256
   LPTR = StrPtr(sConnectionName)
   lNameLenPtr = VarPtr(lNameLen)
   lRetVal = InternetGetConnectedStateEx(lConnectionFlags, ByVal LPTR, ByVal lNameLen, 0&)
   Connected = (lRetVal <> 0)
End Function

The function will use the InternetGetConnectedState function in the wininet DLL file to see if your are connected to the internet. It will return TRUE if it is or FALSE if it isnt.

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.

“If debugging is the process of removing software bugs, then programming must be the process of putting them in.” - Edsger Dijkstra