I have these two methods to get the current travel log entry and to travel to a log entry retrieved by calling the GetTravelLogEntry
method:
public static ITravelLogEntry GetTravelLogEntry(WebBrowser webBrowser)
{
int HRESULT_OK = 0;
SHDocVw.IWebBrowser2 axWebBrowser = (SHDocVw.IWebBrowser2)webBrowser.ActiveXInstance;
IServiceProvider psp = axWebBrowser as IServiceProvider;
if (psp == null) throw new Exception("Could not get IServiceProvider.");
IntPtr oret = IntPtr.Zero;
int hr = psp.QueryService(ref SID_STravelLogCursor, ref IID_ITravelLogStg, out oret);
if ((oret == IntPtr.Zero) || (hr != HRESULT_OK)) throw new Exception("Failed to query service.");
ITravelLogStg tlstg = Marshal.GetObjectForIUnknown(oret) as ITravelLogStg;
if (null == tlstg) throw new Exception("Failed to get ITravelLogStg");
ITravelLogEntry ptle = null;
hr = tlstg.GetRelativeEntry(0, out ptle);
if (hr != HRESULT_OK) MessageBox.Show("Failed to get travel log entry with error " + hr.ToString("X"));
Marshal.ReleaseComObject(tlstg);
return ptle;
}
public static void TravelToTravelLogEntry(WebBrowser webBrowser, ITravelLogEntry travelLogEntry)
{
int HRESULT_OK = 0;
SHDocVw.IWebBrowser2 axWebBrowser = (SHDocVw.IWebBrowser2)webBrowser.ActiveXInstance;
IServiceProvider psp = axWebBrowser as IServiceProvider;
if (psp == null) throw new Exception("Could not get IServiceProvider.");
IntPtr oret = IntPtr.Zero;
int hr = psp.QueryService(ref SID_STravelLogCursor, ref IID_ITravelLogStg, out oret);
if ((oret == IntPtr.Zero) || (hr != HRESULT_OK)) throw new Exception("Failed to query service.");
ITravelLogStg tlstg = Marshal.GetObjectForIUnknown(oret) as ITravelLogStg;
if (null == tlstg) throw new Exception("Failed to get ITravelLogStg");
hr = tlstg.TravelTo(travelLogEntry);
if (hr != HRESULT_OK) MessageBox.Show("Failed to travel to log entry with error " + hr.ToString("X"));
Marshal.ReleaseComObject(tlstg);
}
The WebBrowser
here is a .NET WebBrowser
control. When calling ITravelLogStg::TravelTo
inside the TravelToTravelLogEntry
method I'm getting a 0x80004002, which according to this page is a Interface not supported
error. Am I doing something wrong?
PD: I took most of this code from here.
Well you are trying to navigate to the current entry in the travel log which doesn't make much sense as you are already there. I could reproduce the error for this specific case and find it not very helpful, too.
But using anything else then 0 as first parameter for GetRelativeEntry
and then calling TravelTo
worked as expected.
ITravelLogStg::GetRelativeEntry returns the entry specified by the offset. A positive offset returns an entry after the current entry; a negative offset returns an entry before the current entry. Zero returns the current entry.
(Source: MSDN)
Try modifying hr = tlstg.GetRelativeEntry(0, out ptle);
- the first parameter specifies in which direction you want to navigate. Using other values than 0 should work, e.g. you could use -1 to travel one entry backward.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With