65.9K
CodeProject is changing. Read more.
Home

Access Internet Explorer's History in MFC

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.63/5 (5 votes)

Aug 15, 2004

CPOL
viewsIcon

51231

downloadIcon

2078

Getting the History from Internet Explorer in MFC.

Sample Image - iehistory.gif

Introduction

I just wanted to access the history of Internet Explorer. I found no code anywhere to get it directly, but somehow I managed to combine some of the code and get this working application. The code isn't very great, but it is somewhat useful, you can say. I am not a great writer, so don't expect a good explanation. My coding style is self-explanatory. If you open the IEHistory.h file, you will get to see everything.

[
  #include <atlbase.h>
  #include <comdef.h>
  #include <mshtml.h>
  #include <UrlHist.h>
  #include <afxtempl.h>

  BOOL  GetHistory(CStringList & list)
  {
    STATURL url;
    CString strUrl;
    ULONG uFetched;
    IUrlHistoryStg2Ptr history;
    IEnumSTATURLPtr enumPtr;

    if(FAILED(CoCreateInstance(CLSID_CUrlHistory,
          NULL,
          CLSCTX_INPROC_SERVER,
          IID_IUrlHistoryStg2,
          ( void**)&history)))
          {
            return false ;
          }

          if(FAILED(history->EnumUrls(&enumPtr)))
      return false;

    while(SUCCEEDED(enumPtr->Next(1,&url,&uFetched)))
    {
      if(uFetched==0)
        break;
      strUrl = url.pwcsUrl;
      list.AddTail(strUrl);
    }
    return true;
  }
]

More about me.