c++compiler-errorswininetwinelib

checking internet connection in c++ using internetcheckconnection


I am trying to check internet connection of the user by using internetcheckconnection().

The code:

#include <Wininet.h>
#include <iostream>
#include <string.h>
#include <windows.h>
#pragma comment(lib, "wininet.lib")

int main()
{

    char url[128];
    strcat(url, "http://www.techtoolbox.com");
    bool bConnect = InternetCheckConnection(url, FLAG_ICC_FORCE_CONNECTION, 0);

    if (bConnect) {
        //internet connection exists !

        std::cout << "yes";
    }
    else {
        std::cout << "no ";
    }

    return 0;
}

But many error are coming up like

29 11 C:\Program Files (x86)\Dev-Cpp\MinGW64\x86_64-w64-mingw32\include\Wininet.h [Error] 'LPVOID' does not name a type

30 11 C:\Program Files (x86)\Dev-Cpp\MinGW64\x86_64-w64-mingw32\include\Wininet.h [Error] 'HINTERNET' does not name a type

32 11 C:\Program Files (x86)\Dev-Cpp\MinGW64\x86_64-w64-mingw32\include\Wininet.h [Error] 'WORD' does not name a type and 431 more .

I have already installed Wininet.lib, but still these error are coming . It would be kind of you if you could solve this easy problem :) .


Solution

  • LPVOID, HINTERNET and other types from your error messages are declared in windows.h. You should rearrange includes to fix these errors:

    #include <windows.h>
    #include <Wininet.h>