Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. InternetGetConnectedState problem

InternetGetConnectedState problem

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelp
7 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Spiritofamerica
    wrote on last edited by
    #1

    I want to see what kind of connection a computer has. To this end I am using the InternetGetConnectedState function(if you have any better ideas I am all ears). char * tip_de_conexiune(void) { char respuns[1024]; DWORD tip_de_conexiune; InternetGetConnectedState(&tip_de_conexiune,0); switch(tip_de_conexiune) { case INTERNET_CONNECTION_LAN: { strcpy(respuns,"lan"); MessageBox(0,"lan","lan",MB_OK); } break; case INTERNET_CONNECTION_MODEM: { strcpy(respuns,"dialup"); MessageBox(0,"modem","modem",MB_OK); } break; case INTERNET_CONNECTION_OFFLINE: { strcpy(respuns,"offline"); MessageBox(0,"offline","proxy",MB_OK); } break; case INTERNET_CONNECTION_CONFIGURED: { strcpy(respuns,"configurat"); MessageBox(0,"configured","proxy",MB_OK); } break; } MessageBox(0,"a","b",MB_OK); return respuns; } this works but it returns none of the predefined values either when I am on or offline. I have a dialup connection. any other way of doing this? or what is wrong with this?

    J I D 3 Replies Last reply
    0
    • S Spiritofamerica

      I want to see what kind of connection a computer has. To this end I am using the InternetGetConnectedState function(if you have any better ideas I am all ears). char * tip_de_conexiune(void) { char respuns[1024]; DWORD tip_de_conexiune; InternetGetConnectedState(&tip_de_conexiune,0); switch(tip_de_conexiune) { case INTERNET_CONNECTION_LAN: { strcpy(respuns,"lan"); MessageBox(0,"lan","lan",MB_OK); } break; case INTERNET_CONNECTION_MODEM: { strcpy(respuns,"dialup"); MessageBox(0,"modem","modem",MB_OK); } break; case INTERNET_CONNECTION_OFFLINE: { strcpy(respuns,"offline"); MessageBox(0,"offline","proxy",MB_OK); } break; case INTERNET_CONNECTION_CONFIGURED: { strcpy(respuns,"configurat"); MessageBox(0,"configured","proxy",MB_OK); } break; } MessageBox(0,"a","b",MB_OK); return respuns; } this works but it returns none of the predefined values either when I am on or offline. I have a dialup connection. any other way of doing this? or what is wrong with this?

      J Offline
      J Offline
      Jose Lamas Rios
      wrote on last edited by
      #2

      Spiritofamerica wrote: what is wrong with this? Each of those values is a bit flag. The result contains one or more of them. If you use a switch on the result you are checking for each of them but excluding the possibility of combinations. Try something like this instead:

      CString sFlags;
      if (tip_de_conexiune & INTERNET_CONNECTION_LAN)
        sFlags += "Lan ";
      if (tip_de_conexiune & INTERNET_CONNECTION_MODEM)
        sFlags += "Modem ";
      if (tip_de_conexiune & INTERNET_CONNECTION_OFFLINE)
        sFlags += "Offline ";
      if (tip_de_conexiune & INTERNET_CONNECTION_CONFIGURED)
        sFlags += "Configured ";
       
      AfxMessageBox(sFlags);

      -- jlr http://jlamas.blogspot.com/[^]

      S 1 Reply Last reply
      0
      • S Spiritofamerica

        I want to see what kind of connection a computer has. To this end I am using the InternetGetConnectedState function(if you have any better ideas I am all ears). char * tip_de_conexiune(void) { char respuns[1024]; DWORD tip_de_conexiune; InternetGetConnectedState(&tip_de_conexiune,0); switch(tip_de_conexiune) { case INTERNET_CONNECTION_LAN: { strcpy(respuns,"lan"); MessageBox(0,"lan","lan",MB_OK); } break; case INTERNET_CONNECTION_MODEM: { strcpy(respuns,"dialup"); MessageBox(0,"modem","modem",MB_OK); } break; case INTERNET_CONNECTION_OFFLINE: { strcpy(respuns,"offline"); MessageBox(0,"offline","proxy",MB_OK); } break; case INTERNET_CONNECTION_CONFIGURED: { strcpy(respuns,"configurat"); MessageBox(0,"configured","proxy",MB_OK); } break; } MessageBox(0,"a","b",MB_OK); return respuns; } this works but it returns none of the predefined values either when I am on or offline. I have a dialup connection. any other way of doing this? or what is wrong with this?

        I Offline
        I Offline
        includeh10
        wrote on last edited by
        #3

        the return value is 0x12 always as I tested. includeh10

        S 1 Reply Last reply
        0
        • J Jose Lamas Rios

          Spiritofamerica wrote: what is wrong with this? Each of those values is a bit flag. The result contains one or more of them. If you use a switch on the result you are checking for each of them but excluding the possibility of combinations. Try something like this instead:

          CString sFlags;
          if (tip_de_conexiune & INTERNET_CONNECTION_LAN)
            sFlags += "Lan ";
          if (tip_de_conexiune & INTERNET_CONNECTION_MODEM)
            sFlags += "Modem ";
          if (tip_de_conexiune & INTERNET_CONNECTION_OFFLINE)
            sFlags += "Offline ";
          if (tip_de_conexiune & INTERNET_CONNECTION_CONFIGURED)
            sFlags += "Configured ";
           
          AfxMessageBox(sFlags);

          -- jlr http://jlamas.blogspot.com/[^]

          S Offline
          S Offline
          Spiritofamerica
          wrote on last edited by
          #4

          thanks man it works now when I am online it correctly shows modem configured as in the 2nd and 4th ifs in your code :) but when I am offline it shows nothing it does not show offline why is this man? and everybody else that might know?

          1 Reply Last reply
          0
          • I includeh10

            the return value is 0x12 always as I tested. includeh10

            S Offline
            S Offline
            Spiritofamerica
            wrote on last edited by
            #5

            how did you test includeh10?

            I 1 Reply Last reply
            0
            • S Spiritofamerica

              I want to see what kind of connection a computer has. To this end I am using the InternetGetConnectedState function(if you have any better ideas I am all ears). char * tip_de_conexiune(void) { char respuns[1024]; DWORD tip_de_conexiune; InternetGetConnectedState(&tip_de_conexiune,0); switch(tip_de_conexiune) { case INTERNET_CONNECTION_LAN: { strcpy(respuns,"lan"); MessageBox(0,"lan","lan",MB_OK); } break; case INTERNET_CONNECTION_MODEM: { strcpy(respuns,"dialup"); MessageBox(0,"modem","modem",MB_OK); } break; case INTERNET_CONNECTION_OFFLINE: { strcpy(respuns,"offline"); MessageBox(0,"offline","proxy",MB_OK); } break; case INTERNET_CONNECTION_CONFIGURED: { strcpy(respuns,"configurat"); MessageBox(0,"configured","proxy",MB_OK); } break; } MessageBox(0,"a","b",MB_OK); return respuns; } this works but it returns none of the predefined values either when I am on or offline. I have a dialup connection. any other way of doing this? or what is wrong with this?

              D Offline
              D Offline
              David Crow
              wrote on last edited by
              #6

              See here also.


              "One must learn from the bite of the fire to leave it alone." - Native American Proverb

              1 Reply Last reply
              0
              • S Spiritofamerica

                how did you test includeh10?

                I Offline
                I Offline
                includeh10
                wrote on last edited by
                #7

                UINT uValue=InternetGetConnectedState(); CString cs; cs.Format("0x%X, %d",uValue,uValue); MessageBox("Hello",cs,MB_OK); ------------------------- I use broadband at home. includeh10 -- modified at 19:55 Sunday 28th August, 2005

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups