Использование Win Inet .h для загрузки дает мне ошибки - PullRequest
0 голосов
/ 20 марта 2020

Я хочу скачать с WinInet.h, но это дает мне множество ошибок в моем новом проекте. В более старых проектах это было не так.

Вот мой код:

string DownloadString(string URL) {
    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")

И здесь вы можете увидеть ошибки. do do

1 Ответ

0 голосов
/ 20 марта 2020

Вы должны соблюдать эту последовательность (windows.h до wininet.h):

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

#pragma comment(lib, "wininet.lib")
#pragma comment(lib, "user32.lib")
...