开发者

LNK2019: Error. unresolved external symbol in C++ program using InternetOpen InternetReadFIle

开发者 https://www.devze.com 2023-01-20 04:15 出处:网络
I have tried writing a simple program to get information from a website.I can\'t compile as I get the LNK2019 error for InternetReadFile, InternetOpenUrl, etc. and e.g.

I have tried writing a simple program to get information from a website. I can't compile as I get the LNK2019 error for InternetReadFile, InternetOpenUrl, etc. and e.g.

1>GetInternetInfo.obj : error LNK2019: unresolved external symbol _imp_InternetReadFile@16 referenced in function _main

I assume that means 开发者_Go百科I did not define these functions, that I did not include the correct library. I thought including #include would fix it, but it does not seem to help. I am running this on Visual Studio 2010 using C++. Below is my program. Any help is appreciated.

#include <string>
#include <iostream>
#include <fstream>
#include <windows.h>
#include <wininet.h>
#include <winsock.h>
#include <stdio.h>
#include <stdarg.h>

using namespace std;

int main()      
{
HINTERNET hOpen, hURL;
LPCWSTR NameProgram = L"Webreader";             //      LPCWSTR == Long Pointer to Const Wide String 
LPCWSTR Website;                    
char file[101];
unsigned long read;

//Always need to establish the internet connection with this funcion.  
  if ( !(hOpen = InternetOpen(NameProgram, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0 )))
    {
    cerr << "Error in opening internet" << endl;
    return 0;
    }                       
Website = L"http://www.google.com";
hURL = InternetOpenUrl( hOpen, Website, NULL, 0, 0, 0 );            //Need to open the URL


InternetReadFile(hURL, file, 100, &read);
while (read == 100)
    {
    InternetReadFile(hURL, file, 100, &read);
    file[read] = '\0';
    cout << file;
    }

cout << endl;
InternetCloseHandle(hURL);
return 0;
}


Please include "Wininet.lib" in your project settings.

Project->Properties->Configuration Properties->Linker->Input->Additional Dependencies


You can also add this line to your code after include section instead of adding library to the properties:

#pragma comment(lib, "wininet.lib")


Did you link to wininet.lib?

http://msdn.microsoft.com/en-us/library/aa385103(VS.85).aspx

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号