CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 6 of 8 FirstFirst ... 345678 LastLast
Results 76 to 90 of 111
  1. #76
    Join Date
    Nov 2003
    Posts
    39
    Originally posted by anima_sg
    means the error is not defined by the socket.............. i am uploading the code
    There are some problems with this program!

    Under Win98, when the first time the internet connection is tested, the dial-up dialog box pops up!

    Under WinXp: if you have more dial-up connections setted up, the 'Network connection' dialog box pops up to select the ISP, to wich you want to connect!!!

    Waiting for solutions!
    Thanks!

  2. #77
    Join Date
    Mar 2000
    Location
    Birmingham, England
    Posts
    2,520
    When using wininet functions, the autodialer will be displayed if the user has configured dial-up-networking and is not connected. This is one of the issues of trying to detect a connection invisibly.

    You can overcome this though!

    The autodialer is configured in the registry, so it can be turned off/on at your will before calling into the wininet functions.

    The following code is from my own connection class which I don't want to publish in its entirety because it isn't the greatest code i ever wrote, and it's by no means the complete solution we're all looking for Take a look at the registry sections to see that i am turning the autodialer off, then back on (if it was on originally) after checking the connection. I actually give the user a choice in the UI as to whether they want DUN launched if they are not connected - "Initiate a DUN connection when not connected?".

    Hopefully the code will illustrate the principal - if not, ask questions and i'll try to break it down.

    Code:
    byte CInternetConnexion::DetectWithAutodial(byte byteAutodial /* = IC_ENABLEAUTODIAL */)
    {
    	LOG("CInternetConnexion::DetectWithAutodial() Enter");
    
    	CString s;
    	HKEY    hKey;
    	DWORD   dwDial, dwDialType = REG_DWORD, dwDialSize = 4, dwNew = 0;
    	byte    byteConnected = IC_DISCONNECTED;
    
    	if(byteAutodial == IC_DISABLEAUTODIAL)
    	{
    		if(RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", 0, KEY_QUERY_VALUE | KEY_SET_VALUE, &hKey) != ERROR_SUCCESS)
    	    {
    			LOG("Cannot open Internet Settings");
    			LOG("CInternetConnexion::Detect() Exit <false>");
    			return byteConnected;
    		}
                                                    
    		if(RegQueryValueEx(hKey, "EnableAutodial", NULL, &dwDialType, (BYTE *) &dwDial, &dwDialSize ) == ERROR_SUCCESS )
    		{
    			if(RegSetValueEx( hKey, "EnableAutodial", NULL, dwDialType, (BYTE *) &dwNew, dwDialSize ) != ERROR_SUCCESS)
    			{
    				LOG("Cannot disable EnableAutodial");
    				LOG("CInternetConnexion::Detect() Exit <false>");
    				return byteConnected;
    			}
    		}
    		else
    		{
    			LOG("Cannot disable EnableAutodial");
    			LOG("CInternetConnexion::Detect() Exit <false>");
    			return byteConnected;
    		}
    	}
    
    #ifdef _DEBUG
    	CTime t;
    	t = CTime::GetCurrentTime();
    	s.Format("OpenURL started at %02d.%02d:%02d\n", t.GetHour(), t.GetMinute(), t.GetSecond());
    	TRACE((LPCTSTR)s);
    #endif
    
    	// start up a thread to check for a connection
    	m_tParams.lpURL          = (LPCTSTR)m_sUrl;
    	m_tParams.pByteConnected = &byteConnected;
    	DWORD dwThreadID;
    	HANDLE hThread = CreateThread(NULL, NULL, CheckConnection, &m_tParams, 0, &dwThreadID);
    	
    	// two choices ...
    	if(byteAutodial == IC_DISABLEAUTODIAL)
    	{
    		// there is no possibility of an autodial
    		// so wait for 5 seconds, or until the thread returns - whichever comes soonest
    		WaitForSingleObject(hThread, TIMEOUT);
    	}
    	else
    	{
    		// wait until the thread exits - no timeout used here.
    		// this is because the user may have launched an autodialer and maybe trying to 
    		// connect to the internet now.  It would be a bit rude to just give up ...
    		// This will timeout eventually, or finish when the user makes the connection.
    		WaitForSingleObject(hThread, INFINITE);
    	}
    
    #ifdef _DEBUG
    	t = CTime::GetCurrentTime();
    	s.Format("OpenURL finished at %02d.%02d:%02d\n", t.GetHour(), t.GetMinute(), t.GetSecond());
    	TRACE((LPCTSTR)s);
    #endif
    
    	if(byteAutodial == IC_DISABLEAUTODIAL)
    	{
    		// no need to error check this key, we know it exists now ...
    		RegSetValueEx( hKey, "EnableAutodial", NULL, dwDialType, (BYTE *) &dwDial, dwDialSize);
    		RegCloseKey(hKey);
    	}
    
    #ifdef LOGGING_ON
    	byteConnected == IC_CONNECTED ? s.Format("Connected to internet") : s.Format("Not connected to internet");
    	LOG(s);
    #endif
    	
    	LOG("CInternetConnexion::DetectWithAutodial() Exit");
    
    	return byteConnected;
    }

    Jase

    www.slideshowdesktop.com
    View your images and photos on your desktop with ease using SlideShow Desktop, the desktop wallpaper manager for Microsoft Windows.
    ...

  3. #78
    Join Date
    Jan 2004
    Posts
    1

    Detecting an internet connection

    i am having a shared internet connection on LAN with a local server connected to cable net. i wanted to check internet connection with the remote server before putting a request for a particular page in my partner project. The code given below worked for my purpose,

    CInternetSession session;
    CStdioFile* myfile;
    try
    {
    myfile=session.OpenURL("http://www.indosoftsys.com");
    MessageBox("Internet Connection Exits");
    }
    catch(CInternetException* ie)
    {
    char errMsg[80];
    ie->GetErrorMessage(errMsg,80);
    strcat(errMsg,"Check your internet connection or Server name");
    MessageBox(errMsg);
    }

  4. #79
    Join Date
    Feb 2002
    Location
    Krispl, Austria
    Posts
    197
    Try this. It works with a LAN connection but I can't test with dial up

    #include "Iphlpapi.h"

    MIB_IPFORWARDROW BestRoute;

    DWORD dwResult = GetBestRoute(inet_addr("62.232.0.152"), 0, &BestRoute);

    it returns 0 when the NIC is enabled and 1003 when disabled or unplugged.

  5. #80
    Join Date
    Feb 2002
    Location
    Krispl, Austria
    Posts
    197
    Try this. It returns 0 when NIC is connected and 1003 when disabled/unplugged.

    #include "Iphlpapi.h"

    MIB_IPFORWARDROW BestRoute;

    DWORD dwResult = GetBestRoute(inet_addr("62.232.0.152"), 0, &BestRoute);

  6. #81
    Join Date
    May 1999
    Location
    Southern California
    Posts
    12,266

    Re: Detecting an internet connection

    Originally posted by je_e_tu
    i am having a shared internet connection on LAN with a local server connected to cable net. i wanted to check internet connection with the remote server before putting a request for a particular page in my partner project. The code given below worked for my purpose,
    This thread is already 6 pages. I think it would have been better if a new thread in this forum were used to ask this question instead of adding the question to this thread.
    Last edited by Sam Hobbs; January 8th, 2004 at 09:04 AM.
    "Signature":
    My web site is Simple Samples.
    C# Corner Editor

  7. #82
    Join Date
    Mar 2000
    Location
    Birmingham, England
    Posts
    2,520

    Re: Re: Detecting an internet connection

    Originally posted by Sam Hobbs
    This thread is already 6 pages. I think it would have been better if a new thread in this forum were used to ask this question instead of adding the question to this thread.
    I think it is entirely pertinent to ask the question here, as it is in context with the rest of thread...

    It would be better to discuss this topic and possible solutions within the same context, rather than to fragment it across several posts, making any future miracle cure harder to find.

    Jase

    www.slideshowdesktop.com
    View your images and photos on your desktop with ease using SlideShow Desktop, the desktop wallpaper manager for Microsoft Windows.
    ...

  8. #83
    Join Date
    Mar 2000
    Location
    Birmingham, England
    Posts
    2,520
    Originally posted by Bob Sheep
    Try this. It works with a LAN connection but I can't test with dial up

    #include "Iphlpapi.h"

    MIB_IPFORWARDROW BestRoute;

    DWORD dwResult = GetBestRoute(inet_addr("62.232.0.152"), 0, &BestRoute);

    it returns 0 when the NIC is enabled and 1003 when disabled or unplugged.
    Hi Bob

    Thanks for your suggestion

    I'm sorry to say that it doesn't work ...

    I can turn my broadband modem off, ensuring no connection to the inet, yet it will still say that i am connected. Perhaps it provides a good measure of whether i am connected to a network, I haven't tested it from this perspective. However, there is no possible way of reaching the ip address in your code, yet it still returns 0.

    Jase

    www.slideshowdesktop.com
    View your images and photos on your desktop with ease using SlideShow Desktop, the desktop wallpaper manager for Microsoft Windows.
    ...

  9. #84
    Join Date
    Feb 2002
    Location
    Krispl, Austria
    Posts
    197
    I think the problem is the fact that the network card is active and that as far as the computer is concerned indicates it has an internet connection. It does not seem to care that there is nothing further on than this. I get the same result as you when I connect to a hub. The NIC is active and says I'm connected even though the hub goes nowhere. I think you're going to have to use the connect/wait/retry solution as there's no way to detect the presence of valid routes further down the line from the NIC.

  10. #85
    Join Date
    Feb 2002
    Location
    Krispl, Austria
    Posts
    197
    Why do people constantly slag each other off on these forums.
    Sorry I joined this one.

    Bye (forever)

  11. #86
    Join Date
    Aug 2000
    Posts
    215
    I am not sure Jase but take a look on function InternetGetConnectedState:

    http://support.microsoft.com:80/supp...NoWebContent=1

  12. #87
    Join Date
    Mar 2000
    Location
    Birmingham, England
    Posts
    2,520
    Originally posted by Bob Sheep
    Why do people constantly slag each other off on these forums.
    Sorry I joined this one.
    I don't see anybody "slagging" anybody off Bob.

    Sam is simply putting forward a point of view on how best to organise threads and questions.
    I don't happen to agree with him in this case, but I don't see that anybody here has been violated.

    Bye (forever)
    Why? You have good information to contribute - and nobody has said anything to offend you. If you don't like a post, the best thing to do is just ignore it - pretend it wasn't posted.

    Jase

    www.slideshowdesktop.com
    View your images and photos on your desktop with ease using SlideShow Desktop, the desktop wallpaper manager for Microsoft Windows.
    ...

  13. #88
    Join Date
    Mar 2000
    Location
    Birmingham, England
    Posts
    2,520

    Re: Re: Re: Re: Detecting an internet connection

    Originally posted by Sam Hobbs
    Is the new question the same question as the original question or is it different (whether related or not)?
    Hi Sam

    The post you have quoted is not a question, it is a suggestion for how to detect an internet connection - which is what this thread asks for.

    I agree with you in principal Sam - but in this case your objection does not seem reasonable. Perhaps you quoted the wrong post?

    Jase

    www.slideshowdesktop.com
    View your images and photos on your desktop with ease using SlideShow Desktop, the desktop wallpaper manager for Microsoft Windows.
    ...

  14. #89
    Join Date
    May 1999
    Location
    Southern California
    Posts
    12,266

    Re: Re: Re: Re: Re: Detecting an internet connection

    Originally posted by jase jennings
    The post you have quoted is not a question, it is a suggestion for how to detect an internet connection - which is what this thread asks for.

    I agree with you in principal Sam - but in this case your objection does not seem reasonable. Perhaps you quoted the wrong post?
    I think you are correct; I made a mistake. I don't know why I thought it was a question.

    Since this is the first and only post from je_e_tu, I have made a bad impression on je_e_tu. I am sorry. I hope je_e_tu continues to help.
    "Signature":
    My web site is Simple Samples.
    C# Corner Editor

  15. #90
    Join Date
    Mar 2000
    Location
    Birmingham, England
    Posts
    2,520

    Re: Re: Re: Re: Re: Re: Detecting an internet connection

    Originally posted by Sam Hobbs
    I think you are correct; I made a mistake. I don't know why I thought it was a question.

    Since this is the first and only post from je_e_tu, I have made a bad impression on je_e_tu. I am sorry. I hope je_e_tu continues to help.
    No problem Sam. I also hope he continues to contribute. Same goes for Bob Sheep.

    Jase

    www.slideshowdesktop.com
    View your images and photos on your desktop with ease using SlideShow Desktop, the desktop wallpaper manager for Microsoft Windows.
    ...

Page 6 of 8 FirstFirst ... 345678 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured