URLHIST Interfaces

 

The Header-file Urlhist.h is translated to delphi and included in TUrlHistory Component. Here is a short description of the interfaces:

 

StatUrl

 
STATURL = record
   cbSize: DWORD;
   pwcsUrl: DWORD;
   pwcsTitle: DWORD;
   ftLastVisited: FILETIME;
   ftLastUpdated: FILETIME;
   ftExpires: FILETIME;
   dwFlags: DWORD;
   end;

Staturl contains information about the enumerated entry in Urlhistory.

CbSize: Size of StatUrl structure.

 pwcsUrl
: Pointer to a 0-terminated string containing the url.

 pwcsTitel : Pointer to a 0-terminated string containing the titel.

ftLastVisited : Date/time the page was last visited. Even if it only was read from cache.

ftLastUpdated: Date/time the page was last actually read.

ftExpires: Date/time the page will be deletes from urlhistory.

dwFlags:

STATURLFLAG_ISCACHED Flag on the dwFlags parameter of the STATURL structure indicating that the item is in the cache.
STATURLFLAG_ISTOPLEVEL Flag on the dwFlags parameter of the STATURL structure indicating that the item is a top-level item.

To convert url and title to strings, you can use

 

Title:=PWidechar(Pointer(r.pwcsTitle));

To convert FILETIME to TDateTime:
var
l: Integer;
lft: TFileTime;
begin
FileTimeToLocalFiletime(Ft, lft);
FileTimeToDosDateTime(lft, Longrec(l).Hi, Longrec(l).Lo);
result := FiledateToDatetime(l);
end;

 

IEnumStatUrl

 

IEnumSTATURL = interface(IUnknown)
['{3C374A42-BAE4-11CF-BF7D-00AA006946EE}']
function Next(celt: Integer; out rgelt; var pceltFetched: PLongint): HResult; stdcall;
function Skip(celt: Integer): HResult; stdcall;
function Reset: HResult; stdcall;
function Clone(out ppenum: IEnumSTATURL): HResult; stdcall;
function SetFilter(poszFilter: PWideChar; dwFlags: Integer): HResult; stdcall;
end;

Clone:

Creates a duplicate enumerator containing the same enumeration state as the current one.

Returns S_OK if successful, or E_POINTER if ppEnum is an invalid pointer.

ppEnum duplicate of the enumerator.

 

Next:

Retrieves the specified number of staturl records in the enumeration sequence.

Returns one of the following values:
S_OK Successful.
E_POINTER The rgelt pointer is invalid.
S_FALSE There are no more StatUrl to retrieve.

celt
Number of staturl  records to place in the rgelt array.
rgelt
Array in which to place staturl records.
pcFetched
Actual number of staturl records placed in the array.

 

Reset:

Resets the enumeration sequence to the beginning.

Returns S_OK if successful.

This method affects the return value of the next call to the IEnumStatUrl.Next method.

 

Skip:

Skips a specified number of Call objects in the enumeration sequence.

Returns one of the following values:
S_OK Success.
E_INVALIDARG celt is zero.
S_FALSE The celt value exceeds the number of Staturl records remaining in the enumeration.


celt
Number of UrlHistory entries to skip.

This method affects the return value of the next call to the IEnumStatUrl.Next method.

 

SetFilter:



Define filter for enumeration. IEnumSTATURL.Next  compares the specified URL with each URLin the history list to find matches. IEnumSTATURL.Next then copies the list of matches to a buffer. This method is used to specify the URL to compare:

SetFilter('http://',0)  retrieves only entries starting with 'http.//'. 

 

IUrlHistoryStg

This interface manages Internet Explorer history for the current user.

IUrlHistoryStg = interface(IUnknown)
['{3C374A41-BAE4-11CF-BF7D-00AA006946EE}']
function AddUrl(pocsUrl: PWideChar; pocsTitle: PWideChar; dwFlags: Integer): HResult; stdcall;
function DeleteUrl(pocsUrl: PWideChar; dwFlags: Integer): HResult; stdcall;
function QueryUrl(pocsUrl: PWideChar; dwFlags: Integer; var lpSTATURL: STATURL): HResult; stdcall;
function BindToObject(pocsUrl: PWideChar; var riid: TIID; out ppvOut: Pointer): HResult; stdcall;
function EnumUrls(out ppenum: IEnumSTATURL): HResult; stdcall;
end;

 

AddUrl:

Places the specified URL into the history. If the URL does not exist in the history, an entry is created in the history. If the URL does exist in the history, it is overwritten. IE/Webbrowser call this function when a document is loaded.

Ex: 

AddUrl(PWideChar('http://www.microsoft.com'), PWidechar('Microsoft Corporation',0);

Flags: not implemented



BindToObject:

Not Implemented.

 

DeleteUrl:

Delete a url from the history folder.

DeleteUrl(PWideChar('http://www.microsoft.com'),0);

Flags: not implemented.

 

QueryUrl:

QueryUrl is called whenever the IE/Webbrowser wants to know if a links has been visited before.  That means a call for every link on a page about to be displayed, so the color of link (visited/not visited) can be determined.  

Return S_OK if the url is in history folder.
 
Flags:
STATURL_QUERYFLAG_ISCACHED The specified URL is in the content cache.
STATURL_QUERYFLAG_NOURL Space for the URL is not allocated when querying for STATURL.
STATURL_QUERYFLAG_NOTITLE Space for the Web page's title is not allocated when querying for STATURL.
STATURL_QUERYFLAG_TOPLEVEL The item is a top-level item.

 

 

EnumUrls:

Returns an instance of IEnumStatUrl:

 
I := CreateComObject(ClsId_CUrlHistory) as IUrlHistoryStg2;
I.EnumUrls(Enum);
Enum.SetFilter('http://', 0);
while enum.next(1, r, X) = S_OK do begin
Inc(Row);
StringGrid1.RowCount := Row + 1;
Stringgrid1.Cells[0, Row] := DateTimeToStr(FileTimeToDt(r.ftLastVisited));
Stringgrid1.Cells[1, Row] := PWidechar(Pointer(r.pwcsTitle));
Stringgrid1.Cells[2, Row] := PWidechar(Pointer(r.pwcsUrl));
Stringgrid1.Cells[3, Row] := DateTimeToStr(FileTimeToDt(r.ftLastUpdated));
Stringgrid1.Cells[4, Row] := DateTimeToStr(FileTimeToDt(r.ftExpires));
end;

 

IUrlHistoryStg2

 

IUrlHistoryStg2 = interface(IUrlHistoryStg)
['{AFA0DC11-C313-11D0-831A-00C04FD5AE38}']
function AddUrlAndNotify(pocsUrl: PWideChar; pocsTitle: PWideChar; dwFlags: Integer;
fWriteHistory: Integer; var poctNotify: Pointer;
const punkISFolder: IUnknown): HResult; stdcall;
function ClearHistory: HResult; stdcall;
end;

 

AddUrlAndNotify:

                              Not Implemented

 

ClearHistory:

Deletes all entries in history.

 


 

The webbrowser makes a QueryInterface on IOleClientSite to get the IServiceProvider Interface. The IServiceProvider is an interface that gives you a way to obtain other interfaces that are related to the objet but not directly. Then webbrowser call IServiceProvider.QueryService(SID_STopLevelBrowser, IID_IUrlHistoryStg,  UrlHist) to get IUrlHistoryStg interface.


Links:

IEnumStatUrl Interface

IUrlHistoryStg Interface