Link to home
Start Free TrialLog in
Avatar of nikolaosk
nikolaoskFlag for Greece

asked on

read all the History items of Internet Explorer+delphi

hi there experts!!!!

i need a function in delphi to return me all the items in the history folder especially in the TODAY folder.
for example in my history in my today folder i have the entries:

1)www.expert-exchange.com
2)www.bbc.co.uk
3)www.borland.com

i need a function to return me all these entries.


urgent help needed!!!!!!

thanks a lot in advance.
Avatar of Russell Libby
Russell Libby
Flag of United States of America image

Have you checked the paq from:

https://www.experts-exchange.com/questions/21251955/Read-Index-dat-files.html

If you use the UrlCache code provided, you can iterate all the history items by using the following:

var  listHistory:   TStringList;
begin

  listHistory:=TStringList.Create;
  try
     with TUrlCache.Create do
     begin
        GetEntries(utVisited, listHistory);
        Free;
     end;
     // The listHistory now contains all the visited links
     // Just strip the "Visited: " from each line start

  finally
     listHistory.Free;
  end;

end;

--

Regards,
Russell

Avatar of nikolaosk

ASKER

Russel thanks for your help.

i have two questions for you.

1) i used of course the urlcache unit. do i have to include the

INTERNET_CACHE_ENTRY_INFOA = record e.t.c in that unit?

2)when i use the code posted in the https://www.experts-exchange.com/questions/21251955/Read-Index-dat-files.html

i get back a million of things. using the code above i get nothing back. what i want is just the url pages visited in the Today file. i always need to get the result in a variable. i am using this code in a delphi dll. so i have a function inside the dll like

readtodayvisitedurls.

then i call this function from an external application.
so i cannot have memos and things like that, everything must be returned in as a string or integer.

i changed your code a little bit but i get nothing back

***************
var  listHistory:   TStringList;
str:string;
begin

  listHistory:=TStringList.Create;
  try
     with TUrlCache.Create do
     begin
        GetEntries(utVisited, listHistory);
        str:=listHistory.CommaText
        showmessage(str);

        Free;
     end;
     // The listHistory now contains all the visited links
     // Just strip the "Visited: " from each line start

  finally
     listHistory.Free;
  end;

end;


***********


Russell sorry i mistyped your name again...
No problem on the name. To the questions.

1 - No, its already included in wininet.pas
2 - When you get back all those items, do any items start with "visited:"?

I can modify the code to just return todays history, but I need to know first that it *is* obtaining the history items. Also, is you language set to english or something else? Little more info and we should be able to resolve this.

Russell

Ok.... better alternative. This will return exactly what you see in IE / or Explorer "History" virtual folder. Fills in a TStrings (can also pass a TStringList) list and returns the count of items.

Russell

----


unit IEHistory;

interface

uses
  Windows, SysUtils, Classes, ComObj, ActiveX, ShlObj;

function GetHistoryToday(List: TStrings): Integer;

implementation

function GetHistoryToday(List: TStrings): Integer;
var  pvDesktop:        IShellFolder;
     pvFolder:         IShellFolder;
     pvToday:          IShellFolder;
     pvEnumToday:      IEnumIDList;
     pvEnumHist:       IEnumIDList;
     pvMalloc:         IMalloc;
     pidlHistory:      PItemIDList;
     pidlToday:        PItemIDList;
     pidlItem:         PItemIDList;
     lpValue:          TStrRet;
     lpItem:           TStrRet;
     szValue:          String;
     cbCount:          Cardinal;

     function StrRetToStr(StrRet: TStrRet): String;
     begin
        case StrRet.uType of
           STRRET_CSTR    :  SetString(result, StrRet.cStr, lstrlen(StrRet.cStr));
           STRRET_OFFSET  :  SetLength(result, 0);
           STRRET_WSTR    :  result:=StrRet.pOleStr;
        else
           SetLength(result, 0);
        end;
     end;

begin

  // Check list
  if Assigned(List) then
  begin
     // Lock list
     List.BeginUpdate;
     // Resource protection
     try
        // Clear the list
        List.Clear;
        // Get malloc
        if (SHGetMalloc(pvMalloc) = S_OK) then
        begin
           // Get desktop folder
           if (SHGetDesktopFolder(pvDesktop) = S_OK) then
           begin
              // Get history pidl
              if (SHGetSpecialFolderLocation(GetDesktopWindow, CSIDL_HISTORY, pidlHistory) = S_OK) then
              begin
                 // Bind to folder interface
                 if (pvDesktop.BindToObject(pidlHistory, nil, IID_IShellFolder, pvFolder) = S_OK) then
                 begin
                    // Locate the folder for "Today"
                    if (pvFolder.EnumObjects(0, SHCONTF_FOLDERS or SHCONTF_INCLUDEHIDDEN, pvEnumHist) = S_OK) then
                    begin
                       // Enumerate items
                       while (pvEnumHist.Next(1, pidlItem, cbCount) = S_OK) do
                       begin
                          // Get display name of pidl
                          if (pvFolder.GetDisplayNameOf(pidlItem, SHGDN_NORMAL or SHGDN_INFOLDER, lpValue) = S_OK) then
                          begin
                             // Resource protection
                             try
                                // Check for "Today"
                                if (CompareText(StrRetToStr(lpValue), 'Today') = 0) then
                                begin
                                   // Switch pidls
                                   pidlToday:=pidlItem;
                                   // Bind to folder  interface
                                   if (pvFolder.BindToObject(pidlToday, nil, IID_IShellFolder, pvToday) = S_OK) then
                                   begin
                                      // Get enumerator for "Today" folder
                                      if (pvToday.EnumObjects(0, SHCONTF_FOLDERS or SHCONTF_NONFOLDERS or SHCONTF_INCLUDEHIDDEN, pvEnumToday) = S_OK) then
                                      begin
                                         // Enumerate items
                                         while (pvEnumToday.Next(1, pidlItem, cbCount) = S_OK) do
                                         begin
                                            // Get the url
                                            if (pvToday.GetDisplayNameOf(pidlItem, SHGDN_NORMAL or SHGDN_INFOLDER, lpItem) = S_OK) then
                                            begin
                                               // Resource protection
                                               try
                                                  // Get the string value
                                                  szValue:=StrRetToStr(lpItem);
                                                  // Check URL string
                                                  if (Length(szValue) > 0) then List.Add(szValue);
                                               finally
                                                  // Free string memory
                                                  if (lpItem.uType = STRRET_WSTR) then pvMalloc.Free(lpItem.pOleStr);
                                               end;
                                            end;
                                            // Free memory
                                            CoTaskMemFree(pidlItem);
                                         end;
                                         // Release interface
                                         pvEnumToday:=nil;
                                      end;
                                      // Release interface
                                      pvToday:=nil;
                                   end;
                                   // Free memory
                                   CoTaskMemFree(pidlToday);
                                   // Done processing
                                   break;
                                end;
                             finally
                                // Free string memory
                                if (lpValue.uType = STRRET_WSTR) then pvMalloc.Free(lpValue.pOleStr);
                             end;
                          end;
                          // Free the pidl
                          CoTaskMemFree(pidlItem);
                       end;
                       // Release interface
                       pvEnumHist:=nil;
                    end;
                    // Release interface
                    pvFolder:=nil;
                 end;
                 // Free memory
                 pvMalloc.Free(pidlHistory);
              end;
              // Release interface
              pvDesktop:=nil;
           end;
           // Release interface
           pvMalloc:=nil;
        end;
     finally
        // Unlock the list
        List.EndUpdate;
     end;
     // Return list count
     result:=List.Count;
  end
  else
     // No list
     result:=(-1);

end;

end.
Seven days? Any comments?

yes sorry..

i tried your alternative...

is this IEHistory unit the main unit.

how i am going to see it working?

i just need to have a button on a form and then click it and see what i get back. then i change the code a bit to fit in the dll.

what i did is that i opened a new project and i placed button in a form.
should i add that unit you wrote above to the program? and then how i call those functions from the event click of the button?
thanks
ASKER CERTIFIED SOLUTION
Avatar of Russell Libby
Russell Libby
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
spot on as always. this is exactly what i wanted. i get all the urls i visited in the virtual today history folder.thanks