Access IE Cache via API

zhaozj2021-02-08  248

Access IE Cache via an API We know that IE will save the content of the remote host in the unit for later access to this unit when using IE to browse the web. Here's how to implement all saved content in Cache through Delphi programming. If you are more familiar with Windows API programming, you should know that there are generally two ways to traversal access, one is to define a callback function, then pass the callback function address to the traversal function, and call the callback function once when it is traversed to a content. For example, the ENUMWINDOWS function. The other is to build a handle with an API function, then use this shank as a parameter of the traversal function, we can retrieve false, such as FindFirstFile, and FindNextFile functions by repeated calling traversal functions. The traversal of IE Cache is the second method, that is, first call FindFirstURLCACHEENTRYEX, if the success is successfully returned, then the function returns FALSE by repeating the FindNextURLCACAENTRYEX, so that all files in Cache can be used. Traversing. Let's take a look at the program, build a new project, then join two TButton components and two TListbox components in Form1, and the full code of Form1 is as follows:

Unit unit1;

Interface

Uses Windows, Messages, Sysutils, Classes, Graphics, Controls, Forms, Dialogs, Wininet, Stdctrls

type TForm1 = class (TForm) Button1: TButton; ListBox1: TListBox; ListBox2: TListBox; Button2: TButton; procedure Button1Click (Sender: TObject); procedure Button2Click (Sender: TObject); private function FindNextEntrys (Handle: Integer): Boolean; {Private declarations}} {public declarations} END;

Var Form1: TFORM1;

IMPLEMENTATION

{$ R * .dfm} function tform1.findNextenTRYS (Handle: Integer): boolean; var T: PinternetCachentryInfo; D: DWORD; begin D: = 0; FindNextURLCachentryex (Handle, NIL, @D, nil, nil, nil); GetMem (T, D); Try if FindNextURLCAENTRYEX (Handle, T, @d, nil, nil, nil) The begin listbox1.items.add (t.lpszsourceurlName); listbox2.Items.add (t.lpszlocalFileName); Result: = True; end else result: = false; finally freemem (t, d) end; End;

procedure TForm1.Button1Click (Sender: TObject); var H: Integer; T: PInternetCacheEntryInfo; D: DWORD; begin D: = 0; FindFirstUrlCacheEntryEx (nil, 0, NORMAL_CACHE_ENTRY, 0, nil, @ D, nil, nil, nil) GetMem (t, d); try h: = findfirsturlcachentryex (nil, 0, normal_cache_entry, 0, t, @d, nil, nil, nil); if (h = 0) THEN ELSE BEGINTRYS (H) ; FindCloseUrlCache (H); end finally FreeMem (T, D) end; end; procedure TForm1.Button2Click (Sender: TObject); var URL: String; begin If ListBox1.ItemIndex> = 0 then begin URL: = ListBox1.Items. Strings [listbox1.itemindex]; self.caption: = url; if deleteurlcacheentry (Pchar (URL)) Then ListBox1.Items.delete (ListBox1.ItemIndex); end;

End.

Run the program, click Button1, you can list all the URLs corresponding to the files in Cache and list the corresponding file names in the listbox2 can be listed in ListBox1. Select a list in ListBox1, then click Button2 to remove the item from the cache. Look at the program below, the FindFirstURLCACHEENTRYX function is defined in Delphi as follows:

function FindFirstUrlCacheEntryExA (lpszUrlSearchPattern: PAnsiChar; dwFlags: DWORD; dwFilter: DWORD; GroupId: GROUPID; lpFirstCacheEntryInfo: PInternetCacheEntryInfo; lpdwFirstCacheEntryInfoBufferSize: LPDWORD; lpGroupAttributes: Pointer; {must be nil} pcbGroupAttributes: LPDWORD; {must be nil} lpReserved: Pointer {must NIL}): THANDLE; STDCALL;

转载请注明原文地址:https://www.9cbs.com/read-1168.html

New Post(0)