This article shows how to read a file from Internet Explorer's cache, and write a file to the cache.
Reading from the cache
Retrieving the local cache file name of a URL is simple. You call
GetUrlCacheEntryInfo with the URL, and it will return the local file name. The function will return
TRUE if the URL is in the cache, and
FALSE otherwise. Then, you simply read the page and display it, or do whatever you want with it. Alternatively, you could use the function
RetrieveUrlCacheEntryStream to return the file or stream directly to your application.
DWORD dwBufferSize = 4096;
LPINTERNET_CACHE_ENTRY_INFO lpCacheEntry =
(LPINTERNET_CACHE_ENTRY_INFO) new char[dwBufferSize];
lpCacheEntry->dwStructSize = dwBufferSize;
&dwBufferSize) == TRUE)
Writing files to the cache
Writing files to the cache is a little more complicated. It requires a couple function calls. One method is to use
URLDownloadToCacheFile. I am behind a proxy, and so
URLDownloadToFile will not work for me. The method I use is just as simple. You first call
CreateUrlCacheEntry with the URL and file type and a holder for the cache file name. The function will return a cache file name of where the URL is to be copied. Next, you write the data to the returned cache file. I use a simple local test page as the source of the file to be written, and copy its contents to the cache file. Finally, you call
CommitUrlCacheEntry to finalize the entry into the cache. When calling this method, you specify the URL, the cache file name returned in
CreateUrlCacheEntry, the expired and modified time if known, and a simple header. Use this header if none is known:
(LPBYTE)"HTTP/1.0 200 OK\r\n\r\n".
lpszFileName,0) == TRUE)
ifstream fp_read("testme.html", ios_base::in);
ofstream fp_write(lpszFileName, ios_base::out);
while(fp_read.eof() != true)
if((int)ch == 0x0D)
ftExpireTime.dwHighDateTime = 0;
ftExpireTime.dwLowDateTime = 0;
ftModifiedTime.dwHighDateTime = 0;
ftModifiedTime.dwLowDateTime = 0;
(LPBYTE)"HTTP/1.0 200 OK\r\n\r\n",
20, NULL, NULL) == TRUE)
That's all there is to it!
Programming using MFC and ATL for almost 12 years now. Currently studying Operating System implementation as well as Image processing. Previously worked on DSP and the use of FFT for audio application. Programmed using ADO, ODBC, ATL, COM, MFC for shell interfacing, databasing tasks, Internet items, and customization programs.