ITravelLogStg :: TravelTo with error 0x80004002

I have these two methods to get the current travel log entry and go to the log entry obtained when the GetTravelLogEntry method was GetTravelLogEntry :

  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); } 

WebBrowser here is the .NET WebBrowser . When calling ITravelLogStg::TravelTo inside the TravelToTravelLogEntry method TravelToTravelLogEntry I get 0x80004002, which according to this page is an Interface not supported error. Am I doing something wrong?

PD: I took most of this code from here .

+6
source share
2 answers

Well, you are trying to go to the current entry in the travel log, which does not make much sense since you are already there. I could reproduce the error for this particular case and find it also not very useful.

But using something else, then 0 as the first parameter to GetRelativeEntry , and then calling TravelTo worked as expected.

ITravelLogStg :: GetRelativeEntry returns the record specified at the offset. A positive offset returns the record after the current record; a negative offset returns the record before the current record. Zero returns the current record.

(Source: MSDN )

Try changing hr = tlstg.GetRelativeEntry(0, out ptle); - The first parameter indicates in which direction you want to move. Using values ​​other than 0 should work, for example. you can use -1 to move one record back.

+1
source

I think your problem is with what you pass to the TravelTo method. Have you tried passing simple integer values ​​to find out if you can get past this?

0
source

Source: https://habr.com/ru/post/900353/


All Articles