VB6 realizes network communication detection

xiaoxiao2021-03-06  99

Private sub flow_load ()

If Isconnected = True Then

Msgbox ("You have connected Internet!")

END IF

IF isconnected = false kil

Msgbox ("You haven't connected Internet!")

END IF

End Sub

Option expedition

/ * Related API declarations and definitions * /

Public Declare Function RaseNumConnections Lib "Rasapi32.dll" Alias ​​"RasenumConnectionsa" (LPRASCON AS ANY, LPCB AS Long, LPCCONNECTIONS As Long) AS Long

Public Declare Function RasgetConnectStatus Lib "Rasapi32.dll" Alias ​​"RasgetConnectStatusa" (Byval Hrascon As Long, LPSTATUS AS ANY) AS Long

/ * Settings of constants and variables * /

Public const ras95_maxentryname = 256

Public const ras95_maxdevicetype = 16

Public const ras95_maxdevicename = 32

Public Type Rasconn95

DWSIZE As Long

Hrascon As Long

SzenTryName (ras95_maxentryname) as byte

SzdevicetyPE (RAS95_MAXDEVICETY) AS BYTE

Szdevicename (RAS95_MAXDEVICENAME) AS BYTE

End Type

Public Type RasconnStatus95

DWSIZE As Long

RasconnState As Long

DWERROR As Long

SzdevicetyPE (RAS95_MAXDEVICETY) AS BYTE

Szdevicename (RAS95_MAXDEVICENAME) AS BYTE

End Type

/ * Function isconnected returns a state of communication, if true is true * /

Public function isconnected () as boolean

DIM TRASCON (255) as rasconn95

DIM LG As Long

DIM LPCON AS Long

DIM RETVAL AS Long

DIM TSTATUS As RasconnStatus95

TrasoScon (0) .dwsize = 412

LG = 256 * Trascon (0) .dwsize

Retval = RaseNumConnections (trascon (0), LG, LPCON)

IF RetVal <> 0 THEN

MSGBOX "error"

EXIT FUNCTION

END IF

TSTATUS.DWSIZE = 160

Retval = raasgetConnectStatus (trascon (0)

.hrascon, TSTATUS

IF tstatus.rasconnstate = & h2000 Then

Isconnected = true

Else

Isconnected = false

END IF

END FUNCTION

转载请注明原文地址:https://www.9cbs.com/read-103725.html

New Post(0)