Detecting (internet) connection status

This is a discussion on Detecting (internet) connection status within the Windows Programming forums, part of the Platform Specific Boards category; I'm writing a program that relies on activation whenever the user goes online. I was wondering if there's a possible ...

  1. #1
    Registered User Coder's Avatar
    Join Date
    Aug 2001
    Location
    Cairo, Egypt
    Posts
    128

    Detecting (internet) connection status

    I'm writing a program that relies on activation whenever the user goes online. I was wondering if there's a possible way to register my app with windows so that it gets a message (notification) whenever the user goes online (like dap/icq/whatever).

    Thanks

  2. #2
    Banned maes's Avatar
    Join Date
    Aug 2001
    Posts
    744
    I would do it like this. write a program that loads with windows(with the regestry or something). set a timer and let it check every minute or so if there is a connection. Not sure, but I think this is the way ICQ works.
    here is the code for checking if you are connected to the net. I know this code worked a few months ago. And now it doesn't work anymore, don't know why(haven't search either). But I'll post it anyway. Maybe someone finds the error or maybe it works for you (if it does, let me know please)
    Code:
    #include <ras.h>
    
    
    bool IsConnected()
    {
       LPRASCONN TRasCon;
       RASCONNSTATUS Tstatus;
    
       DWORD lg;
       DWORD lpcon;
       bool lReturn;
    
       TRasCon->dwSize = 412;
       lg = 256 * TRasCon->dwSize;
       lReturn = false;
    
       if( RasEnumConnections(TRasCon, &lg, &lpcon) == 0 )
       {
           Tstatus.dwSize = 160;
           RasGetConnectStatus(TRasCon->hrasconn, &Tstatus);
    
           lReturn = ( Tstatus.rasconnstate == 0x2000 );
       }
    
       return( lReturn );
    }

  3. #3
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    Code:
    #include <windows.h>
    #include <tchar.h>
    #include <ras.h>
    #include <raserror.h>
    
    
    int WINAPI WinMain(HINSTANCE hThisInst, HINSTANCE hPrevInst, 
                       LPSTR lpszArgs, int nWinMode)
    {
    	RASCONN TRasCon ;
        RASCONNSTATUS Tstatus;
    	DWORD lg = 0;
    	DWORD lpcon = 0;
    	TCHAR szStat[50],szString[] = _T("This system is ");
      
       
    	TRasCon.dwSize = sizeof(TRasCon);
    	lg = TRasCon.dwSize;//Set size for array of connections
    
    
    	if( RasEnumConnections(&TRasCon, &lg, &lpcon) == 0 )//Find connection
    		{
    			Tstatus.dwSize = sizeof(Tstatus);
    			RasGetConnectStatus(TRasCon.hrasconn, 
    				&Tstatus);//Find Connection status
    
    			_tcscpy(szStat,
    				Tstatus.rasconnstate == RASCS_Connected?
    				_T("Connected"):_T("Not Connected"));
    			
    			_tcscat(szString,szStat);
    			
    			MessageBox(0,szString,_T("Connection status"),MB_OK);
    		}
    
    	return 0;
    
    }
    That should work...

  4. #4
    Registered User johnnie2's Avatar
    Join Date
    Aug 2001
    Posts
    186
    InetIsOffline() returns true if the system is not currently connected to the Internet, and false if it is. Include intshcut.h and link with url.lib.
    "Optimal decisions, once made, do not need to be changed." - Robert Sedgewick, Algorithms in C

  5. #5
    Registered User Coder's Avatar
    Join Date
    Aug 2001
    Location
    Cairo, Egypt
    Posts
    128

    Arrow

    Originally posted by maes
    write a program that loads with windows(with the regestry or something). set a timer and let it check every minute or so if there is a connection
    This is exactly the method I'm currently using. I have a thread that checks the connection status every specified period of time.

    I was looking for some (better) way that doesn't keep the CPU doing useless operations (I know it doesn't slow down noticably, but I just hate to reserve any CPU power when I don't need it).

    I thought there would be some way that relies on windows messages/events/whatever...

    Thanks for the help & the code
    I guess I'll have to keep it as it is ( for now )
    Muhammad Haggag

  6. #6
    amr
    amr is offline
    Registered User
    Join Date
    Mar 2002
    Posts
    1

    hi all

    I think the function InternetConnectionStatus is the best one for this.
    Ok , Coder have you received the email for the aoi or not that says that the test is at 16 March means after 3 days from now.
    ok
    amr

  7. #7
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    I'm not ramiliar with this ras.h lib. Does somebody have a link explaining the functions and usage of this lib?
    1978 Silver Anniversary Corvette

  8. #8
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    Remote Access Server (I think)....as in DialUpServer...

    Do a search on Google

  9. #9
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    Hmmm...so it's like WinSock?
    1978 Silver Anniversary Corvette

  10. #10
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    Originally posted by Garfield
    Hmmm...so it's like WinSock?
    Not entirely...but they do overlap of course

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. connection status monitoring
    By George2 in forum Tech Board
    Replies: 0
    Last Post: 12-11-2006, 08:02 AM
  2. Troubles with Sockets
    By cornholio in forum Windows Programming
    Replies: 6
    Last Post: 10-26-2005, 05:31 AM
  3. Headers that use each other
    By nickname_changed in forum C++ Programming
    Replies: 7
    Last Post: 10-03-2003, 04:25 AM
  4. internet connection autostart
    By beely in forum Tech Board
    Replies: 9
    Last Post: 06-24-2003, 07:08 AM
  5. Determining status of a network connection?
    By Cat in forum Windows Programming
    Replies: 0
    Last Post: 06-04-2003, 05:30 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21