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
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Detecting internet connection using InternetGetConnectedState in VC++

Detecting internet connection using InternetGetConnectedState in VC++

Scheduled Pinned Locked Moved C / C++ / MFC
helpcsharpquestionc++json
6 Posts 3 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.
  • K Offline
    K Offline
    Kogee San
    wrote on last edited by
    #1

    Hello again everyone Before that i would like to tell u all that im really new and dumb to .NET. Hope you guys can help me. I tried to search the solution to my problem but still couldnt find anything. What im trying to do is to create a really simple internet connection detection which is running under a win32 console. The program will detect if there is any connection to the internet, if yes then it will print yes. If no connection then it will print out no connection using printf() statement. I know that the InternetGetConnectedState API can help me. but still im not so sure on how to use it. Really dumb me...the scenario is like this I already link the VC++ project to the Wininet.lib since it required that lib and a header file called Wininet.h (as refered in MSDN). I try to code just by adding the header file to the source code #include "stdio.h" #include "Wininet.h" void main() { } using the code above, compile, it generates more than 100 error which particularly made the compiler to stop compiling due to error exceeds 100. all of the errors come from the Wininet.h header file. The first error was "error C2061: syntax error:Identifier 'HINTERNET'. The question is, am i missing something. Does VC++ supports this API? I've search the internet (forums..etc) and all of them were implemented using C# or VB. Is there any source code samples using this API which can be run only in a simple win32 console application? Thank you everyone. Really appreciate any help. Thanks again.

    N 1 Reply Last reply
    0
    • K Kogee San

      Hello again everyone Before that i would like to tell u all that im really new and dumb to .NET. Hope you guys can help me. I tried to search the solution to my problem but still couldnt find anything. What im trying to do is to create a really simple internet connection detection which is running under a win32 console. The program will detect if there is any connection to the internet, if yes then it will print yes. If no connection then it will print out no connection using printf() statement. I know that the InternetGetConnectedState API can help me. but still im not so sure on how to use it. Really dumb me...the scenario is like this I already link the VC++ project to the Wininet.lib since it required that lib and a header file called Wininet.h (as refered in MSDN). I try to code just by adding the header file to the source code #include "stdio.h" #include "Wininet.h" void main() { } using the code above, compile, it generates more than 100 error which particularly made the compiler to stop compiling due to error exceeds 100. all of the errors come from the Wininet.h header file. The first error was "error C2061: syntax error:Identifier 'HINTERNET'. The question is, am i missing something. Does VC++ supports this API? I've search the internet (forums..etc) and all of them were implemented using C# or VB. Is there any source code samples using this API which can be run only in a simple win32 console application? Thank you everyone. Really appreciate any help. Thanks again.

      N Offline
      N Offline
      Naveen
      wrote on last edited by
      #2

      Kogee San wrote:

      it generates more than 100 error which particularly made the compiler to stop compiling due to error exceeds 100. all of the errors come from the Wininet.h header file.

      modify ur code as follows #include "stdio.h" #include <windows.h> #include "Wininet.h" void main() { }

      nave [OpenedFileFinder]

      K 1 Reply Last reply
      0
      • N Naveen

        Kogee San wrote:

        it generates more than 100 error which particularly made the compiler to stop compiling due to error exceeds 100. all of the errors come from the Wininet.h header file.

        modify ur code as follows #include "stdio.h" #include <windows.h> #include "Wininet.h" void main() { }

        nave [OpenedFileFinder]

        K Offline
        K Offline
        Kogee San
        wrote on last edited by
        #3

        wow. It really works. Thanks. Just wanna ask if you dont mind. Why do we need to add windows.h. I always see codes which add windows.h eventhough it is just a hello world printf statement. Just kinda curious. Thanks again.

        N D K 3 Replies Last reply
        0
        • K Kogee San

          wow. It really works. Thanks. Just wanna ask if you dont mind. Why do we need to add windows.h. I always see codes which add windows.h eventhough it is just a hello world printf statement. Just kinda curious. Thanks again.

          N Offline
          N Offline
          Naveen
          wrote on last edited by
          #4

          Kogee San wrote:

          Why do we need to add windows.h.

          This is because the Wininet.h file use some other data types such as LPVOID. This is defined in some other header files. For getting the definition of such items we need to include the windows.h

          nave [OpenedFileFinder]

          1 Reply Last reply
          0
          • K Kogee San

            wow. It really works. Thanks. Just wanna ask if you dont mind. Why do we need to add windows.h. I always see codes which add windows.h eventhough it is just a hello world printf statement. Just kinda curious. Thanks again.

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

            Kogee San wrote:

            I always see codes which add windows.h eventhough it is just a hello world printf statement.

            Then those programs included it unnecessarily.

            "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

            "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

            1 Reply Last reply
            0
            • K Kogee San

              wow. It really works. Thanks. Just wanna ask if you dont mind. Why do we need to add windows.h. I always see codes which add windows.h eventhough it is just a hello world printf statement. Just kinda curious. Thanks again.

              K Offline
              K Offline
              Kogee San
              wrote on last edited by
              #6

              Thanks guys for your help and comments. Really appreciate it.

              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