Click here to Skip to main content
15,879,239 members
Articles / Programming Languages / VBScript

Read the Cache in VB

Rate me:
Please Sign up or sign in to vote.
1.75/5 (4 votes)
21 Dec 2003CPOL 58.3K   659   11   5
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.

VBScript
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:

VBScript
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)


Written By
United States United States
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.

-

Comments and Discussions

 
GeneralIt's only a matter of ... Pin
Chris Meech22-Dec-03 4:35
Chris Meech22-Dec-03 4:35 
QuestionWhy DoEvents? Pin
casperOne22-Dec-03 3:36
casperOne22-Dec-03 3:36 
AnswerJust curious ! Pin
UB22-Dec-03 6:55
UB22-Dec-03 6:55 
GeneralRe: Just curious ! Pin
casperOne22-Dec-03 6:58
casperOne22-Dec-03 6:58 
GeneralRe: Just curious ! Pin
UB22-Dec-03 7:04
UB22-Dec-03 7:04 

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

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