简介:
指从指定URL地址读取内容并将读取到的内容保存到特定的文件里。
语法格式:
HRESULT URLDownloadToFile(
LPUNKNOWN pCaller,
LPCTSTR szURL,
LPCTSTR szFileName,
DWORD dwReserved,
LPBINDSTATUSCALLBACK lpfnCB
);
参数:
pCaller:Pointer to the controlling IUnknown interface of the calling Microsoft ActiveX component (if the caller is an ActiveX component).
//该参数为 ActiveX 控件的接口指针,如果当前程序不是 ActiveX 控件则写 NULL 就可以了。
szURL
Pointer to a string value containing the URL to be downloaded. Cannot be set to NULL.
//该参数为要下载的 url 地址,不能为空。
szFileName
Pointer to a string value containing the name of the file to create for bits that come from the download.
//下载文件后,保存的文件名字,包含文件的具体路径信息。
dwReserved
Reserved. Must be set to 0.
//保留字段,必需为0。
lpfnCB
Pointer to the caller's IBindStatusCallback interface. URLDownloadToFile calls this interface's IBindStatusCallback::OnProgress method on a connection activity, including the arrival of data. IBindStatusCallback::OnDataAvailable is never called.
//下载进度状态回调接口的指针。如果要实时监视下载文件的状态那么就要用到这个参数了。
返回值:
S_OK : 成功下载;
E_OUTOFMEMORY:缓冲区长度不够,或者没有足够的内存来完成下载的操作;
INET_E_DOWNLOAD_FAILURE:指定的资源或者回调接口有问题。
实例:
HRESULT hRet = URLDownloadToFile(NULL, "https://s.cctry.com/images/eagle2.png", "D:\\cctry.png", 0, NULL);