c++ - 我应该使用 URLDownloadToFile 吗?

标签 c++ file download

我正在寻找用 C++(在 Windows 上)下载文件的最简单方法。 URLDownloadToFile 听起来不错,不需要我使用 curl 或其他我不需要的胖库 - 这个功能有什么要求?它将在哪个 Windows 上运行?

谢谢!

最佳答案

http://msdn.microsoft.com/en-us/library/ms775123%28VS.85%29.aspx

文档存在是有原因的。

E:只要看一眼文档,它至少需要 Internet Explorer 3.0 和 Windows 95。几乎没有计算机不满足这些要求。

E:这是一个如何使用此功能的示例。您还需要链接 Urlmon.lib 进行编译:

#include "stdafx.h"
#include <stdio.h>
#include <tchar.h>

#include <windows.h>
#include <Urlmon.h>

int _tmain(int argc, _TCHAR* argv[])
{
    printf("URLDownloadToFile test function.\n");

    TCHAR url[] = TEXT("http://google.com");

    printf("Url: %S\n", url);

    TCHAR path[MAX_PATH];

    GetCurrentDirectory(MAX_PATH, path);

    wsprintf(path, TEXT("%s\\index.html"), path);

    printf("Path: %S\n", path);

    HRESULT res = URLDownloadToFile(NULL, url, path, 0, NULL);

    if(res == S_OK) {
        printf("Ok\n");
    } else if(res == E_OUTOFMEMORY) {
        printf("Buffer length invalid, or insufficient memory\n");
    } else if(res == INET_E_DOWNLOAD_FAILURE) {
        printf("URL is invalid\n");
    } else {
        printf("Other error: %d\n", res);
    }

    return 0;
}

关于c++ - 我应该使用 URLDownloadToFile 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5184988/

相关文章:

c++ - wxWidgets EVT_BUTTON函数参数取决于事件来自哪里?

c++ - 在不存在的目录中打开文件 c 与 c++

file - golang 阅读更多 4096 字节

windows - 用于 Bootstrap 文件下载的 AWS CloudFormation 和 Windows Server 2008 R2

linux - 适用于Linux的SAP Netweaver试用版

java - 如何使用 Dropbox API V2 下载特定文件?

c++ - 在C++中退出具有三个线程的两个并发队列

java - 将 C 或 C++ 转换为 Java

c++ - Makefile 的标准 F90 库

html - 如何在 Firefox 中设置文件输入字段的样式?