Note that there are some explanatory texts on larger screens.

plurals
  1. POInternet Explorer Addon Toolbar Button Error
    text
    copied!<p>I am currently developing an IE toolbar button in C# that is supposed to be able to get the contents of the current tab and work with it. However, whenever the button is clicked, the IObjectWithSite.SetSite function is called ( my code will be posted at the end) and returns the following error:</p> <blockquote> <p>Unable to cast COM object of type 'System.__ComObject' to interface type SHDocVw.IWebBrowser2'. This operation failed because the QueryInterface call on the COM componenet for the interface with IID ' </blockquote> <p>The function works properly when a site is loaded, but only throws this error when the button in the tool bar is clicked. As stated before, the SetSite function get called, and then the IOleCommandTarget.Exec function gets called. </p> <p>So, I guess my question is: what do I cast the object that is passed into the SetSite function so that I can access the document on the tab that Internet Explorer currently has open?</p> <p>My current relevant code for those two functions is as follows:</p> <pre><code>int IObjectWithSite.SetSite(object site) { String display = ""; try { browser = (IWebBrowser2)site;} catch (Exception e) { display += e.Message + "\r\n"; } System.Windows.Forms.MessageBox.Show(display); return 0; } int IOleCommandTarget.Exec(IntPtr pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut) { if (form == null) { form = new SomeForm(); form.InputText = ""; } form.ShowDialog(); return 0; } </code></pre> <p>Thanks in advance.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload