Option Explicit

Private Sub Command2_Click()
    frmWebBrowser.brwWebBrowser.Navigate (Me.Text1.Text)
    Unload Me
End Sub

Private Sub Form_Load()

   With Combo1
      '.AddItem "Normal Entry"
      '.ItemData(.NewIndex) = &H1
      '.AddItem "Edited Entry (IE5)"
      '.ItemData(.NewIndex) = &H8
      '.AddItem "Offline Entry"
      '.ItemData(.NewIndex) = &H10
      '.AddItem "Online Entry"
      '.ItemData(.NewIndex) = &H20
      '.AddItem "Stick Entry"
      '.ItemData(.NewIndex) = &H40
      '.AddItem "Sparse Entry (n/a)"
      '.ItemData(.NewIndex) = &H10000
      '.AddItem "Cookies"
      '.ItemData(.NewIndex) = &H100000
      .AddItem "Visited History"
      .ItemData(.NewIndex) = &H200000
      '.AddItem "Default Filter"
      '.ItemData(.NewIndex) = URLCACHE_FIND_DEFAULT_FILTER
      .ListIndex = 0
   End With
   
End Sub

Private Sub Command1_Click()

   Dim numEntries As Long
   Dim cacheType As Long
   
   cacheType = Combo1.ItemData(Combo1.ListIndex)
   
   Label1.Caption = "Working ..."
   Label1.Refresh
   
   List1.Clear
   List1.Visible = False
   
   numEntries = GetCacheURLList(cacheType)
   
   List1.Visible = True
   Label1.Caption = Format$(numEntries, "###,###,###,##0") & "files found"
   
End Sub

Private Sub List1_Click()

   Text1.Text = List1.List(List1.ListIndex)
   
End Sub

Private Function GetCacheURLList(cacheType As Long) As Long
    
   Dim ICEI As INTERNET_CACHE_ENTRY_INFO
   Dim hFile As Long
   Dim cachefile As String
   Dim nCount As Long
   Dim dwBuffer As Long
   Dim pntrICE As Long
   
  'Like other APIs, calling FindFirstUrlCacheEntry or
  'FindNextUrlCacheEntry with an insufficient buffer will
  'cause the API to fail, and its dwBuffer points to the
  'correct size required for a successful call.
   dwBuffer = 0
   
  'Call to determine the required buffer size
   hFile = FindFirstUrlCacheEntry(vbNullString, ByVal 0, dwBuffer)
   
  'both conditions should be met by the first call
   If (hFile = ERROR_CACHE_FIND_FAIL) And _
      (Err.LastDllError = ERROR_INSUFFICIENT_BUFFER) Then
   
     'The INTERNET_CACHE_ENTRY_INFO data type is a
     'variable-length type. It is necessary to allocate
     'memory for the result of the call and pass the
     'pointer to this memory location to the API.
      pntrICE = LocalAlloc(LMEM_FIXED, dwBuffer)
        
     'allocation successful
      If pntrICE Then
         
        'set a Long pointer to the memory location
         CopyMemory ByVal pntrICE, dwBuffer, 4
         
        'and call the first find API again passing the
        'pointer to the allocated memory
         hFile = FindFirstUrlCacheEntry(vbNullString, ByVal pntrICE, dwBuffer)
       
        'hfile should = 1 (success)
         If hFile <> ERROR_CACHE_FIND_FAIL Then
         
           'now just loop through the cache
            Do
            
              'the pointer has been filled, so move the
              'data back into a ICEI structure
               CopyMemory ICEI, ByVal pntrICE, Len(ICEI)
            
              'CacheEntryType is a long representing the type of
              'entry returned, and should match our passed param.
               If (ICEI.CacheEntryType And cacheType) Then
               
                  'extract the string from the memory location
                  'pointed to by the lpszSourceUrlName member
                  'and add to a list
                   cachefile = GetStrFromPtrA(ICEI.lpszSourceUrlName)
                   List1.AddItem cachefile
                   nCount = nCount + 1
               
               End If
               
              'free the pointer and memory associated
              'with the last-retrieved file
               Call LocalFree(pntrICE)
               
              'and again repeat the procedure, this time calling
              'FindNextUrlCacheEntry with a buffer size set to 0.
              'This will cause the call to once again fail,
              'returning the required size as dwBuffer
               dwBuffer = 0
               Call FindNextUrlCacheEntry(hFile, ByVal 0, dwBuffer)
               
              'allocate and assign the memory to the pointer
               pntrICE = LocalAlloc(LMEM_FIXED, dwBuffer)
               CopyMemory ByVal pntrICE, dwBuffer, 4
               
           'and call again with the valid parameters.
           'If the call fails (no more data), the loop exits.
           'If the call is successful, the Do portion of the
           'loop is executed again, extracting the data from
           'the returned type
            Loop While FindNextUrlCacheEntry(hFile, ByVal pntrICE, dwBuffer)
  
         End If 'hFile
         
      End If 'pntrICE
   
   End If 'hFile
   

  'clean up by closing the find handle, as
  'well as calling LocalFree again to be safe
   Call LocalFree(pntrICE)
   Call FindCloseUrlCache(hFile)
   
   GetCacheURLList = nCount
   
End Function

Private Function GetStrFromPtrA(ByVal lpszA As Long) As String

   GetStrFromPtrA = String$(lstrlenA(ByVal lpszA), 0)
   Call lstrcpyA(ByVal GetStrFromPtrA, ByVal lpszA)
   
End Function