Detecting a connection to internet with c++ builder...

I'd like to detect when a connection to the internet is made.
I think it may have to do with OLE but if it may helps I'm using borland c++ builder.
LVL 1
filipecorreiaAsked:
Who is Participating?
 
AlexVirochovskyConnect With a Mentor Commented:
HOWTO: Detecting If You Have a Connection to the Internet
http://support.microsoft.com/support/kb/articles/Q242/5/58.ASP
Alex
0
 
filipecorreiaAuthor Commented:
Probably helpfull but I don't know how to use it...
I tried using the InternetGetConnectedState(...) function but I couldn't manage to make it work. The compiler tells me that it can't recognize that function (am I missing an "include"?).
0
 
AlexVirochovskyCommented:
Sorry, you want for BCB...
1.
You can use the NetMasters Powersock component to retrieve the Local IP
address. If it is "0.0.0.0" then there is no connection.

Example:

void __fastcall TForm1::Button1Click(TObject *Sender)
{
if (Powersock1->LocalIP == "0.0.0.0")
ShowMessage("not connected");
else
ShowMessage(Powersock1->LocalIP);
}
2.
go to http://home.hkstar.com/~sega1/ and install the TCheckConnection
component. It does exactly this.
3. If you know, that it is RAS
  connection, you can use RasEnumConnection API.
Alex

0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
AlexVirochovskyCommented:
BTW: 27PTS???
0
 
filipecorreiaAuthor Commented:
Well...,yes. 27Pts. Is it to much? Is it not enough? I always liked round numbers  :)   but I'm willing to push it a bit higher if I get a pretty good answer...


1. Using the NetMasters Powersock component I always get a non "0.0.0.0" IP even if I'm not connected.

2. I didn't manage to install the TcheckConnection  component. I guess it has to do with the version of BCB. I'm using BCB4 but the TcheckConnection component was made for BCB3 (are the package versions incompatible??, is there a way to make them compatible??).


3. No, it can't be. It has to work with any kind of connection.

Filipe
0
 
filipecorreiaAuthor Commented:
Are you giving up on my question ???
0
 
AlexVirochovskyCommented:
1. About PTS: by EE gradation :
  50 easy ,100 : intermediate, 200 : hard. 27 PTS: supereasy Q??? Of course,
not!
2. TCheckConnection is really BCB3 and
can't use it.
3. RasEnumConnection don't detect LAN connections(is it you case?)
4. For my first idea you must get from MSDN new wininet.H, wininet.dll
(wininet.h i can send you)
4. But about NetMasters: this must  work! It is official recomendation of Borland. But i have problems with time and don't test it: i hve't this component in my BCB4 , must search: 3 days.
Alex  
0
 
AlexVirochovskyCommented:
Now, i tested it. Best way: my 1-st reply, using InternetGetConnectedState.
Example of code:
void __fastcall TForm1::Button1Click(TObject *Sender)
{
  DWORD flags = 0;
  if (InternetGetConnectedState(
      &flags,NULL) == FALSE)
    MessageBeep(-1);
}
But for this you need change wininet.h
and add in LIB directory wininet.lib(for
BCB4, not for VC!)
I can send you this new versions,
but : i don't make it for 27 PTS(and you can reject my reply). Only after
increasing PTS to 300 (minimum) and accepting my answer , write you EMail and i'll send you this stuff.
Alex

0
 
filipecorreiaAuthor Commented:
Sad to say but... I don't have 300Pts available.
I've got 208Pts available and I'm willing to raise from 27 to 170Pts (I don't want to end up with 0Pts) and I will only give them when I'm sure you're solution is working.


If you agree tell me something.


Filipe
0
 
AlexVirochovskyCommented:
Write you EMail and i 'll send you
full project(after a raising to 170 PTS).
0
 
filipecorreiaAuthor Commented:
Adjusted points to 170
0
 
filipecorreiaAuthor Commented:
Send it to filcorproductions@mailcity.com


By the way... Where did you got those new versions? Do you know a place where to get updates?


Filipe
0
 
filipecorreiaAuthor Commented:
It works fine... Thanks.

Do you know where can I find documentation about wininet and what it enables me to do?
I would really apreciate if you could give me some links...

If you have something that can help me please send it to my e-mail(filcorproductions@mailcity.com
)


Filipe Correia
0
 
AlexVirochovskyCommented:
Hi, thanks for PTS.
Next is some facts about wininet and simple example
of creating connect to Internet.
Main source: MSDN and you Window Help file: all functions
with word Internet: it is wininet.
Many examlpes you can find in www.codeguru.com in
Internet programming(but for MFC).
Snippet from
http://www.young.com/Winsock/newbie.html
The era of stand-alone, self-contained applications is rapidly ending. Distributed, networked applications have become critical to meeting business needs in a fast-paced, dynamic world. Until now, building networked Windows applications wasn't easy. But now Microsoft has released a powerful new Windows Internet API (WinInet) that dramatically simplifies the process of creating Internet-enabled Windows applications.

WinInet makes it possible to create Windows applications that can download Web pages, access server applications, upload and download files, and traverse Gopher document systems--allowing developers to build such sophisticated Windows Internet applications as full-fledged Web browsers, home banking applications, and stock portfolio programs.

Essential WinInet is a comprehensive guide to this powerful Windows Internet API. It starts with a tutorial on WinInet basics and a methodical description of the API's protocol-specific functions for HTTP, FTP, and Gopher, then proceeds to explore more advanced topics, examining how WinInet works with other Internet tools and client/server technologies. This book addresses such essential topics as:
.....

Example of creation connection:

HINTERNET Connect()
{
HINTERNET hOpen=InternetOpen(NULL, INTERNET_OPEN_TYPE_PROXY,"ftp=ftp://.....", NULL, 0);
HINTERNET handle=InternetConnect(hOpen, "....",21,"....","....",INTERNET_SERVICE_FTP , NULL, 0);
return handle;
}
some URL:
http://www.skonnard.com/ewininet/
http://www.hallprogramming.com/apis_operating_environments/45.shtml
http://www.bristol.com/support/wu430rn.html
Alex
0
All Courses

From novice to tech pro — start learning today.