Win32 - Check if user is connected to internet

Share your advanced PureBasic knowledge/code with the community.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Win32 - Check if user is connected to internet

Post by BackupUser »

Code updated For 5.20+

Restored from previous forum. Originally posted by MrVainSCL.

Here is a small codesnip to check if you are connected to the internet or not... Maybe usefull for some people trying to write any network based appz.

Here is a normal version:

Code: Select all

; ------------------------------------------------------------
;
; PureBasic Win32 API - CheckInternetConnection - Example v1.0
;
; by MrVainSCL! aka Thorsten   19/Jan/2003    PB v3.51+
;
; ------------------------------------------------------------
;
    If InternetGetConnectedState_(0, 0) 
      result$ = "Online"
    Else
      result$ = "Offline"
    EndIf
    ;
    MessageRequester("Are we connected to the Internet?","We are "+result$,0)
End
;
; ------------------------------------------------------------
Here is a Procedure() version:

Code: Select all

; ------------------------------------------------------------
;
; PureBasic Win32 API - CheckInternetConnection - Example v1.0
;
; by MrVainSCL! aka Thorsten   19/Jan/2003    PB v3.51+
;
; ------------------------------------------------------------
;
    Procedure MyCheckInternetConnection()
        If InternetGetConnectedState_(0, 0) 
          result = 1
        Else
          result = 0
        EndIf
        ;
        ProcedureReturn result
    EndProcedure
    ;
    ; -------- Check if user is connected to internet -------- 
    ;
    If MyCheckInternetConnection() = 1
      state$ = "Online"
    Else
      state$ = "Offline"
    EndIf
    ;
    MessageRequester("Are we connected to the Internet?","We are "+state$,0)
End
;
; ------------------------------------------------------------

Added 00:29 am - Requirements
Windows NT/2000/XP: Included in Windows NT 4.0 or later.
Windows 95/98/Me: Included in Windows 95 or later.
Version: Requires Internet Explorer 4.0 or later.


PIII450, 256MB Ram, 80GB HD + 6,4 GB, RivaTNT, DirectX9.0, SB AWE64, Win2000 + all Updates...

greetz
MrVainSCL! aka Thorsten
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by PB.

> Here is a small codesnip to check if you are connected to the
> internet or not...

This tip won't work on Win 95, for those of you coding for all versions
of Windows. See below for details, and for some other Internet-related
flags:

viewtopic.php?t=4336
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by MrVainSCL.

Uppssss...

thanks for the info and link PB... Havent known that this API call was mentied somewhere before in this forum...

PIII450, 256MB Ram, 80GB HD + 6,4 GB, RivaTNT, DirectX9.0, SB AWE64, Win2000 + all Updates...

greetz
MrVainSCL! aka Thorsten
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Hi-Toro.

According to MSDN, it will work on 95, as long as the user has IE4 or above...


--
See ya,
James L Boyd.
http://www.hi-toro.com/
--
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by PB.

> According to MSDN, it will work on 95, as long as the user has IE4
> or above...

Yes, that why I said "see below for details" in my post. :)
Post Reply