Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Read the Cache in VB

0.00/5 (No votes)
21 Dec 2003 1  
Demonstration uses WinInet methods to read cached URL files

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

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here