Solved

Downloading Internet Files

Posted on 1998-01-23
1
620 Views
Last Modified: 2013-11-20
I am working on an application to download a file from the Internet. I can do this successfully via the http functions but I'd like to put the retrieved file into cache. Does anyone know how to use the URLDownloadToCacheFile() function? Is this the right one? Do I have to be connected to the Internet first before I use it? What gives this command an Internet context? Any sample code anywhere?
0
Comment
Question by:rhans042197
1 Comment
 
LVL 23

Accepted Solution

by:
chensu earned 100 total points
ID: 1314638
Yes, the URLDownloadToCacheFile() function is the right one. The latest Internet Client SDK has more information about the 4th parameter.

dwBufLength
DWORD value that contains the size of the szFileName buffer or a flag. If a flag is set to dwBufLength, the buffer is assumed to be of size MAX_PATH. The flag can be one of the following values:
URLOSTRM_USECACHEDCOPY_ONLY  Only download the resource from the cache.  
URLOSTRM_USECACHEDCOPY  Download the resource from the cache if it is available; otherwise, download it from the Internet.  
URLOSTRM_GETNEWESTVERSION  Download the resource from the Internet, if it is newer, and store it in the cache.  

A simple example:

TCHAR pszFilename[MAX_PATH];

HRESULT hr = ::URLDownloadToCacheFile(NULL,  // for non ActiveX component
                                      _T("http://www.somewhere.com/somefile.dat"),
                                      pszFilename,
                                      URLOSTRM_USECACHEDCOPY,
                                      0,
                                      NULL);

if (SUCCEEDED(hr))
{
    // the file has been successfully downloaded, pszFilename contains the cached file name
}

0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Complete beginner needs help making a cron job 9 129
tripleUp challenge 7 92
Fibonacci challenge 11 136
wordmultiple challenge 12 154
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question