Jump to navigation Jump to search
A high-level call to download a file from a web server and save it to disk. This function is popular with because it implements all the functionality of a downloader in one function call.
HRESULT URLDownloadToFile( LPUNKNOWN pCaller, LPCTSTR szURL, LPCTSTR szFileName, _Reserved_ DWORD dwReserved, LPBINDSTATUSCALLBACK lpfnCB );
- A pointer to the controlling IUnknown interface of the calling ActiveX component, if the caller is an ActiveX component. If the calling application is not an ActiveX component, this value can be set to NULL. Otherwise, the caller is a COM object that is contained in another component, such as an ActiveX control in the context of an HTML page. This parameter represents the outermost IUnknown of the calling component. The function attempts the download in the context of the ActiveX client framework, and allows the caller container to receive callbacks on the progress of the download.
- A pointer to a string value that contains the URL to download. Cannot be set to NULL. If the URL is invalid, INET_E_DOWNLOAD_FAILURE is returned.
- A pointer to a string value containing the name or full path of the file to create for the download. If szFileName includes a path, the target directory must already exist.
- Reserved. Must be set to 0.
- A pointer to the IBindStatusCallback interface of the caller. By using IBindStatusCallback::OnProgress, a caller can receive download status. URLDownloadToFile calls the IBindStatusCallback::OnProgress and IBindStatusCallback::OnDataAvailable methods as data is received. The download operation can be canceled by returning E_ABORT from any callback. This parameter can be set to NULL if status is not required.
This function can return one of these values.
|S_OK||The download started successfully.|
|E_OUTOFMEMORY||The buffer length is invalid, or there is insufficient memory to complete the operation.|
|INET_E_DOWNLOAD_FAILURE||The specified resource or callback interface was invalid.|