Thread: InternetAttemptConnect

  1. #1
    Registered User
    Join Date
    Dec 2007
    Posts
    932

    InternetAttemptConnect

    Whats the reason that if i unplug my internet cable it still returns ERROR_SUCCESS and prints out "Internet available...

    Code:
    #include <cstdio>
    #include <windows.h>
    #include <wininet.h>
    
    
    int main()
    {
       if(InternetAttemptConnect(0) == ERROR_SUCCESS) printf("\nInternet available...\n");
       else printf("Internet unavailable.\n");
    
       return 0;
    }
    Ps i should have posted it in the networking forum. Feel free to deplace it, thanks!
    Using Windows 10 with Code Blocks and MingW.

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    >> Whats the reason that if i unplug my internet cable it still returns ERROR_SUCCESS and prints out "Internet available...

    Not sure. MSDN doesn't provide much detail about how it works. If you're using router and only disconnecting it from the line going out to the internet that might make sense, as your computer would still be able to detect it's IP address, causing InternetAttemptConnect to assume there is a connection. At any rate, there are probably other ways to do this. You could first check that you have an active IP address other than the loop-back, and if so, attempt to open a socket with the destination set to that IP address. I haven't tested it out though, but I'm pretty sure it'd work.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  3. #3
    Registered User
    Join Date
    Dec 2007
    Posts
    932
    Thanks Sebastiani!

    Not much use for this function then.
    Using Windows 10 with Code Blocks and MingW.

  4. #4
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    It is weird that it takes an unused parameter, though. Is that for future compatibility, or current undocumented usage?
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  5. #5
    Registered User
    Join Date
    Dec 2007
    Posts
    932
    Code:
        hInternet = InternetOpen(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL,0);
        if(hInternet == NULL)printf("Internet unavailable.\n");
    Same story with InternetOpen(). Cant check if its NULL.
    Using Windows 10 with Code Blocks and MingW.

  6. #6
    'Allo, 'Allo, Allo
    Join Date
    Apr 2008
    Posts
    639
    It is weird that it takes an unused parameter, though. Is that for future compatibility, or current undocumented usage?
    Probably neither. The argument isn't referenced XP through 7 except to check against 0, and given that the function is mainly intended for dial-up usage (going by the remarks), probably never will be. But who knows.

    Same story with InternetOpen(). Cant check if its NULL.
    InternetOpen and InternetConnect just set up state, no attempts are made until HttpSendRequest or an equivalent is called. I use InternetCheckConnection with a url and the FLAG_ICC_FORCE_CONNECTION flag to check connectedness, and it seems to work correctly.

Popular pages Recent additions subscribe to a feed