我尝试编写一个简单的程序来从网站获取信息。我无法编译,因为我收到 InternetReadFile、InternetOpenUrl 等的 LNK2019 错误,例如
1>GetInternetInfo.obj:错误LNK2019:无法解析的外部符号_imp_InternetReadFile@16 在函数 _main 中引用
我认为这意味着我没有定义这些函数,我没有包含正确的库。我认为包括 #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;
}