我嘗試編寫一個簡單的程序以從網站獲取信息。我無法編譯,因爲我得到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;
}