Click here to Skip to main content
Licence CPOL
First Posted 21 Dec 2003
Views 41,914
Downloads 555
Bookmarked 11 times

Read the Cache in VB

By | 21 Dec 2003 | Article
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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

QUIETTA



United States United States

Member

Hubris is like armor. He is afraid to take on a Coder project for what it may do to him, both financially and to his health.
 
WEB Bowser is a hack that makes it easy to acquire internet content for archival. Its also possible to PROXY it, serving it to the internet as well. Given this capability, people will change the internet again.
 
I envision a programmable server that will acquire content for proxy. Users will then add proxy content to their own, making it available almost as if it were their own. We are already "information collectors." Its the opinions that are getting real hard to find.
 
-

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralIt's only a matter of ... PinmemberChris Meech4:35 22 Dec '03  
QuestionWhy DoEvents? PinmembercasperOne3:36 22 Dec '03  
AnswerJust curious ! PinmemberUB6:55 22 Dec '03  
GeneralRe: Just curious ! PinmembercasperOne6:58 22 Dec '03  
GeneralRe: Just curious ! PinmemberUB7:04 22 Dec '03  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120517.1 | Last Updated 22 Dec 2003
Article Copyright 2003 by QUIETTA
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid