URLHIST 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.
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.
CbSize, dwFlags: Unknown
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. Not really sure how to use this function, but:
SetFilter('http://',0) retrieves only entries starting with 'http.//'.
IUrlHistoryStg
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:
Add url to the history folder. IE/Webbrowser call this function when a document is loaded.
Ex:
AddUrl(PWideChar('http://www.microsoft.com'), PWidechar('Microsoft Corporation',0);
Flags: ???
DeleteUrl:
Delete a url from the history folder.
DeleteUrl(PWideChar('http://www.microsoft.com'),0);
Flags: ???
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: ???
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:
???
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.