Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

InternetGetConnectedState,InternetCheckConnection,InternetAttemptConnect

887 views
Skip to first unread message

Alex

unread,
Nov 1, 1999, 3:00:00 AM11/1/99
to
I am trying to create an FTP component that connects to an FTP server
without any user interaction. I can do this no probs, what I would like it
to do (if possible) is to dynamicallly detect if it needs to dial in or
whether a LAN connection exists. Also, I would like to check to see if a
connection is possible without 'hanging' the app for the Timeout.

I see in the wininet.dll there are the three functions as stated in the
subject. None of them behave as I would expect them to.

Public Declare Function InternetGetConnectedState Lib "wininet.dll" _
(ByRef lpdwFlags As Long, ByVal dwReserved As Long) As Boolean
++>This returns True no matter what, and the lpdwFlags contains 18. This is
regardless of any dial up connections configured. And also if I have the
network connected or not.

Public Declare Function InternetCheckConnection Lib "wininet.dll" Alias
"InternetCheckConnectionA" _
(ByVal lpszUrl As String, ByVal dwFlags As Long, ByVal dwReserved As Long)
As Boolean
++>This returns False every time. I've tried an IP address, a URL address
such as http://www.microsoft.com
I've tried http://xxx.xx.xxx.xxx also with no luck. Always False.

Public Declare Function InternetAttemptConnect Lib "wininet.dll" _
(ByVal dwReserved As Long) As Long
++>This always returns 0 (ERROR_SUCCESS) regardless of what I do.

I presume I am doing something wrong, the question is what?

Which one of these functions do I use? And more precisely how do I use it?

Any help would be appreciated.
--
Alex
Software Developer

"My mind not only wanders,
sometimes it leaves completely."


Nicholas Paldino

unread,
Nov 2, 1999, 3:00:00 AM11/2/99
to
Alex,

You should have mentioned that you were using Internet Explorer 5.

Anyways, for the first function, InternetGetConnectedState returns true
if the computer has the capability to connect to the Internet, not if it is
connected to the internet. The flags that you are getting back, 18, can
only come from one combination, which is INTERNET_RAS_INSTALLED and
INTERNET_CONNECTION_LAN. Is this the case? Are you connected over a lan
and have RAS installed as well?

For the InternetCheckConnection, the documentation states that it
attempts to ping the server that you specify. I dont know about the other
servers that you have tried, but www.microsoft.com does not respond to ping
requests, so the function would return false. If you are finding that the
servers that you are trying to check are honoring ping requests, then you
might want to pass the flag FLAG_ICC_FORCE_CONNECTION,
InternetCheckConnection will not force a new connection if one doesn't
exist.

InternetAttemptConnect tries to connect to the Internet for you. If you
have a LAN, then this is pointless, because an IP address is assigned to
you, and it sees that as a connection to the Internet, and given the
response from the call to the InternetGetConnectedState function, it seems
as if this is the case.

However, I think that you don't need to do any of this. In your call to
InternetOpen, pass the INTERNET_OPEN_TYPE_PRECONFIG flag in to the
dwAccessType parameter. The WinInet libraries will take care of the rest
for you. If the user has a connection through the LAN, then it will use
that, if it is through a dial up connection, it will use that. It already
knows.

Hope this helps.

--
- Nicholas Paldino
- nicholas...@exisconsulting.com

Alex

unread,
Nov 2, 1999, 3:00:00 AM11/2/99
to
Thanks for the pointers. I didn't mention IE5 specifically, because I can't
guarantee that it will be installed. I checked the docs, and I believe
these functions are supported in ANSI from IE3. Anyway, it seems pointless,
when this does not do what I want. I did attempt InternetOpen with
INTERNET_OPEN_TYPE_PRECONFIG with RAS and no LAN. It attempted the
connection, but it apparently tried LAN first, after attempting it popped up
the dialog to dial-in. Perhaps there is a left over in the registry of a
LAN connection. My goal is to end up with a reliable, self-correcting auto
dial in and FTP without any user interaction. There may not even be a
monitor hooked up!

I appreciate the help, but I think I may have to include other API's in
addition to the wininet.

--
Alex
Software Developer

"My mind not only wanders,
sometimes it leaves completely."

Nicholas Paldino <nicholas...@exisconsulting.com> wrote in message
news:#vnBC1TJ$GA.253@cppssbbsa05...

Joseph White

unread,
Nov 14, 1999, 3:00:00 AM11/14/99
to

Nicholas Paldino <nicholas...@exisconsulting.com> wrote in message
news:#vnBC1TJ$GA.253@cppssbbsa05...
[Snip]

>
> Anyways, for the first function, InternetGetConnectedState returns
true
> if the computer has the capability to connect to the Internet, not if it
is
> connected to the internet. > InternetCheckConnection will not force a new

connection if one doesn't
> exist.
>

My experience is that InternetGetConnectedState()
will return TRUE or FALSE depending on when it
last refreshed its internal info.
For example, if you unplug your network cable it
will continue to report true until you actually
fail to connect to something. Then it will report
false. If you plug the cable back in, it will
report false until you try another connection.

Does InternetCheckConnection work through a proxy?


0 new messages