ITravelLogStg::TravelTo fails with error 0x80004002
Asked Answered
G

2

6

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.

Go answered 29/10, 2011 at 20:54 Comment(2)
Have you tried without doing the Marshal.ReleaseComObject(tlstg) ?Pathe
@Simon: I just tried this, it still sometimes fails.Go
B
1

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.

Bandstand answered 2/11, 2011 at 9:52 Comment(8)
Thanks for answering. Actually, I'm navigating to a different page before calling TravelToTravelLogEntry, after calling GetTravelLogEntry.Go
Could that be the problem? Holding on to the entry and then navigating? Maybe this somehow invalidates the interface. Could you obtain the entry after navigating?Bandstand
Well, you don't have an accurate way to know when an entry will be created (don't even mention the DocumentComplete event!). So you don't really know where the entry you are looking for will be. The weird thing is that it sometimes work (after navigating, always) and sometimes doesn't.Go
Maybe I could try iterating through all existing entries and checking for equality to the entry I'm holding and go to that one instead of this one (even though "they are equal"), see what happens.Go
That is definitely worth trying! By the way: which IE version are you using/targeting?Bandstand
Just tried it, still failed sometimes. I'm using IE9, but targeting 7 to 9 (and eventually 10).Go
Did you opt into IE9 mode like described in the following link? This might make a difference. #6915164Bandstand
I've tried 7, 8 and 9 mode. Eventually I'll try 10 mode but I'm sure it won't help.Go
R
0

I think your problem is with what you're passing in to the TravelTo method. Have you tried passing in plain integer values to see if you can get past this?

Rosco answered 8/11, 2011 at 17:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.