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

2024-03-20

我尝试编写一个简单的程序来从网站获取信息。我无法编译,因为我收到 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;
}

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

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

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

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

随机推荐