Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

InternetConnect ALWAYS returns success 1

Status
Not open for further replies.

codefinger

Programmer
Feb 2, 2002
14
US


Declare Function InternetConnect _
Lib "wininet.dll" Alias "InternetConnectA" ( _
ByVal hInternetSession As Long, _
ByVal sServerName As String, _
ByVal nServerPort As Integer, ByVal sUsername As String, _
ByVal sPassword As String, ByVal lService As Long, _
ByVal lFlags As Long, ByVal lContext As Long) As Long


Code:
Public Function OpenConnection() As String

hConnection = InternetConnect(hOpen, Ppn_connectto, _
INTERNET_INVALID_PORT_NUMBER, _
"", "", INTERNET_SERVICE_HTTP, 0, 0)

If hConnection = 0 Then
OpenConnection = "Could not connect to server " &ppn_connectto & ":
" & Err.Description
Exit Function
End If

OpenConnection = "Connection successful!"

End Function


Always returns "Connection successful!", even when cable modem is unplugged!


Any and all assistance greatly appreciated. Thanks in advance.
 
Try this:

Declarations:

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
'
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_MaxDeviceType) As Byte
szDeviceName(RAS95_MaxDeviceName) As Byte
End Type
'
Public Type RASCONNSTATUS95
dwSize As Long
RasConnState As Long
dwError As Long
szDeviceType(RAS95_MaxDeviceType) As Byte
szDeviceName(RAS95_MaxDeviceName) As Byte
End Type


Code:

'A call to the function IsConnected returns true if the computer has established a connection to the internet.

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
'
TRasCon(0).dwSize = 412
lg = 256 * TRasCon(0).dwSize
'
RetVal = RasEnumConnections(TRasCon(0), lg, lpcon)
If RetVal <> 0 Then
MsgBox &quot;ERROR&quot;
Exit Function
End If
'
Tstatus.dwSize = 160
RetVal = RasGetConnectStatus(TRasCon(0).hRasCon, Tstatus)
If Tstatus.RasConnState = &H2000 Then
IsConnected = True
Else
IsConnected = False
End If

End Function



Hope this helps,

John Stephens
 
Thank you, now I have the opposite problem. This code always says I am NOT connected, even while I am (through my cable modem.)

I set a break here:
RetVal = RasGetConnectStatus(TRasCon(0).hRasCon, Tstatus)
If Tstatus.RasConnState = &H2000 Then
IsConnected = True
Else
IsConnected = False
End If

Just before the IF statement, RetVal is 6 and Tstatus.RasConnState remains 0. (I am most curious about the value or variable &H2000. I had always thought &quot;&&quot; was the concatenation operator. What am I missing here?)

Thanks in advance for your kind assistance.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top