InternetCheckConnection()

BlitzPlus Forums/BlitzPlus Programming/InternetCheckConnection()

JoshK(Posted 2005) [#1]
I can't get this API function to work.

Declare Function InternetCheckConnection Lib "wininet.dll" Alias "InternetCheckConnectionA" (ByVal lpszUrl As String, ByVal dwFlags As Long, ByVal dwReserved As Long) As Long


· lpszUrl
[in] Pointer to a string containing the URL to use to check the connection. This value can be set to NULL.

· dwFlags
[in] Unsigned long integer value containing the flag values. FLAG_ICC_FORCE_CONNECTION is the only flag that is currently available. If this flag is set, it forces a connection. A sockets connection is attempted in the following order.
If lpszUrl is non-NULL, the host value is extracted from it and used to ping that specific host.
If lpszUrl is NULL and there is an entry in WinInet's internal server database for the nearest server, the host value is extracted from the entry and used to ping that server.

· dwReserved
[in] Reserved. Must be set to zero.


Returns TRUE if a connection is made successfully, or FALSE otherwise. Use GetLastError to retrieve the error code. ERROR_NOT_CONNECTED is returned by GetLastError if a connection cannot be made or if the sockets database is unconditionally offline.


wininet.decls:
.lib "wininet.dll"
InternetAttemptConnect%() : "InternetAttemptConnect"
InternetCheckConnection%(lpszUrl$,dwFlags,dwReserved) : "InternetCheckConnectionA"


Test program:
Notify InternetCheckConnection("",0,0)
Notify InternetCheckConnection("www.google.com",0,0)
Notify InternetCheckConnection("http://www.google.com",0,0)



Kevin_(Posted 2005) [#2]
Try this...

[Code]
WebPage$="www.blitzbasic.com"
Net=Web_Connection_Available(WebPage$)
If Net=True
Print "Connection Available"
Else
Print "Not available"
EndIf
WaitKey()
End

; **********************************************

Function Web_Connection_Available(WebPage$)
; Checks to see if an Internet Connection is currently available.
; Returns True if available, otherwise false. Valid web address required.
;
tcp=OpenTCPStream( WebPage$,80 )
CloseTCPStream tcp
If tcp
Return True
Else
Return False
EndIf
End Function
[/Code]

Adjust tcp timeouts if required.


skidracer(Posted 2005) [#3]
Halo, your test program is not calling InternetAttemptConnect ( see msdn Enabling Internet Functionality page linked at bottom of the other commands).


JoshK(Posted 2005) [#4]
I'm actually trying to check to see if a connection exists, without forcing one.


skidracer(Posted 2005) [#5]
InternetGetConnectedState?


JoshK(Posted 2005) [#6]
Ah-ha!