LNK2019:错误。使用InternetOpen的C++程序中无法解析的外部符号InternetReadFIle

LNK2019:错误。使用InternetOpen的C++程序中无法解析的外部符号InternetReadFIle

问题描述:

我尝试编写一个简单的程序以从网站获取信息。我无法编译,因为我得到InternetReadFile,InternetOpenUrl等的LNK2019错误,LNK2019:错误。使用InternetOpen的C++程序中无法解析的外部符号InternetReadFIle

1> GetInternetInfo.obj:错误LNK2019:解析外部符号_ 小鬼 _InternetReadFile @在函数引用_main

16我假定意味着我没有定义这些功能,即我不包括正确的库。我认为包括#include会解决它,但它似乎没有帮助。我正在使用C++在Visual Studio 2010上运行它。以下是我的计划。任何帮助表示赞赏。

#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; 
} 

请在项目设置中包含“Wininet.lib”。

项目 - >属性 - >配置属性 - >连接器 - >输入 - >附加依赖

还可以将此行添加到您的代码包含部分之后的,而不是添加库属性:

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