使用WinInet.h下载给我错误

问题描述 投票:-1回答:1

嘿,所以我想用WinInet.h下载,但这在我的旧项目的新项目中给了我很多错误,而事实并非如此。

这是我的代码:

    HINTERNET interwebs = InternetOpenA("Mozilla/5.0", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, NULL);
    HINTERNET urlFile;
    string rtn;
    if (interwebs) {
        urlFile = InternetOpenUrlA(interwebs, URL.c_str(), NULL, NULL, NULL, NULL);
        if (urlFile) {
            char buffer[2000];
            DWORD bytesRead;
            do {
                InternetReadFile(urlFile, buffer, 2000, &bytesRead);
                rtn.append(buffer, bytesRead);
                memset(buffer, 0, 2000);
            } while (bytesRead);
            InternetCloseHandle(interwebs);
            InternetCloseHandle(urlFile);
            string p = replaceAll(rtn, "|n", "\r\n");
            return p;
        }
    }
    InternetCloseHandle(interwebs);
    string p = replaceAll(rtn, "|n", "\r\n");
    return p;

}

这是我的包含物:

#include "c_api.h"
#include <iostream>
#include <fstream>
#include "termcolor.h"
#include "xor.hpp"
#include <time.h>
#include <wininet.h>
#include <urlmon.h>
#include <Windows.h>
#include <urlmon.h>
#pragma comment(lib, "urlmon.lib")
#pragma comment(lib, "WinInet.lib")

这里您可以看到错误。dodo

c++ c windows download wininet
1个回答
0
投票

您必须遵守此包含序列(windows.h之前的wininet.h):

#include <windows.h>
#include <strsafe.h>
#include <wininet.h>  
// ...

#pragma comment(lib, "wininet.lib")
#pragma comment(lib, "user32.lib")
© www.soinside.com 2019 - 2024. All rights reserved.