Introduction
This easy method uses Wininet
DLL to read a cache file. The demo uses a class object.
This algorithm requires use of InternetOpen
function to initialize the DLL to read from the cache. INTERNET_FLAG_FROM_CACHE
setting forces a new download of the requested files in calls to InternetOpenURL
with a URL set. It reads the file and returns it. It closes all handles.
Private Const INTERNET_OPEN_TYPE_DIRECT = &H1
Private Const INTERNET_FLAG_FROM_CACHE = &H40
Public Function ReadCacheFile(url As String) As String
Dim l&, Buffer$, hOpen&, hFile&, Result&
l = 32768
Buffer = Space(l)
DoEvents
hOpen = InternetOpen(UserAgent, INTERNET_OPEN_TYPE_DIRECT, _
vbNullString, vbNullString, INTERNET_FLAG_FROM_CACHE)
hFile = InternetOpenUrl(hOpen, url, vbNullString, _
ByVal 0&, &0, _
ByVal 0&)
Call InternetReadFile(hFile, Buffer, l, Result&)
Call InternetCloseHandle(hFile)
Call InternetCloseHandle(hOpen)
ReadCacheFile = Left$(StrConv(Buffer, vbUnicode), Result&)
End Function
This line is useful for obtaining unfiltered data such as for getting an applet:
ReadCacheFile = Left$(StrConv(Buffer, vbUnicode), Result&)
In the case of an applet, with conversion to UNICODE it works, without the conversion it will not.
History
- 21st December, 2003: Initial post