MinGW >> C/C++

URLDownloadToFile


main.c

#define WIN32_LEAN_AND_MEAN
#include <tchar.h>
#include <iomanip>
#include <iostream>
#include <urlmon.h>
#include <wininet.h>
#include <windows.h>

int main(int argc, char** argv)
{
    const TCHAR path[] = _T("putty.exe");
    const TCHAR url[] = _T("https://the.earth.li/~sgtatham/putty/latest/w32/putty.exe");

    printf("downloading: %s\n", url);
    printf("to local file: %s\n", path);
    DeleteUrlCacheEntry(url);
    HRESULT hr = URLDownloadToFile(NULL, url, path, 0, NULL);
    printf("hr:0x%x\n", hr);
    return 0;
}

編譯

$ i686-w64-mingw32-g++ -U __STRICT_ANSI__ -o url.exe main.c -lwininet -luuid -lurlmon -static


返回上一頁