Using Wininet

I am learning to use Wininet and have found some code online which looks like this
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include<iostream>
#include<cstring>
#include<wininet.h>

using namespace std;
int main(){
HINTERNET connect = InternetOpen("MyBrowser",INTERNET_OPEN_TYPE_PRECONFIG,NULL, NULL, 0);

   if(!connect){
      cout<<"Connection Failed or Syntax error";
      return 0;
   }

HINTERNET OpenAddress = InternetOpenUrl(connect,"http://localhost/", NULL, 0, INTERNET_FLAG_PRAGMA_NOCACHE|INTERNET_FLAG_KEEP_CONNECTION, 0);

   if ( !OpenAddress )
   {
      DWORD ErrorNum = GetLastError();
      cout<<"Failed to open URL \nError No: "<<ErrorNum;
      InternetCloseHandle(connect);
      return 0;
   }

   char DataReceived[4096];
   DWORD NumberOfBytesRead = 0;
   while(InternetReadFile(OpenAddress, DataReceived, 4096, &NumberOfBytesRead) && NumberOfBytesRead )
   {
           cout << DataReceived;
   }

   InternetCloseHandle(OpenAddress);
   InternetCloseHandle(connect);

   system("PAUSE");
}


However, when I ran it, a lots of error come out


1>c:\program files\microsoft sdks\windows\v6.0a\include\wininet.h(58) : error C2146: syntax error : missing ';' before identifier 'HINTERNET'
1>c:\program files\microsoft sdks\windows\v6.0a\include\wininet.h(58) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files\microsoft sdks\windows\v6.0a\include\wininet.h(58) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
C4430: missing type specifier - int assumed. Note: C++ does not support default-int
................
................
................
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


Could Anyone advise?
You need to link to "Wininet.lib".
How can I link to e Wininet lib? Is it like another line of code or?
Many txs
It can be done with a line of code like #pragma comment (lib, "wininet.lib") for MSVS. You would need to put the entire path to the library into that second argument though.
Topic archived. No new replies allowed.