LNK2019:错误.使用 InternetOpen InternetReadFIle 的 C++ 程序中未解析的外部符号 [英] LNK2019: Error. unresolved external symbol in C++ program using InternetOpen InternetReadFIle

查看:17
本文介绍了LNK2019:错误.使用 InternetOpen InternetReadFIle 的 C++ 程序中未解析的外部符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试编写一个简单的程序来从网站获取信息.我无法编译,因为我收到 InternetReadFile、InternetOpenUrl 等的 LNK2019 错误,例如

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: 未解析的外部符号 _imp_InternetReadFile@16 在函数 _main 中引用

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

我认为这意味着我没有定义这些函数,我没有包含正确的库.我认为包括 #include 会解决它,但它似乎没有帮助.我正在使用 C++ 在 Visual Studio 2010 上运行它.下面是我的程序.任何帮助表示赞赏.

I assume that means 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;
}

推荐答案

请在您的项目设置中包含Wininet.lib".

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

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

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

这篇关于LNK2019:错误.使用 InternetOpen InternetReadFIle 的 C++ 程序中未解析的外部符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆