互联网浏览器加载项工具栏按钮错误 [英] Internet Explorer Addon Toolbar Button Error

查看:162
本文介绍了互联网浏览器加载项工具栏按钮错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在开发的是应该能够得到当前选项卡的内容,并使用它的C#的IE工具栏按钮。然而,只要点击该按钮,IObjectWithSite.SetSite函数被调用(我的代码将在年底公布),并返回以下错误:




无法转换类型
系统.__ ComObject的COM对象的接口类型
SHDocVw.IWebBrowser2。这个操作
失败,因为QueryInterface调用
对IID为
'



接口的COM componenet

该功能工作正常时,一个网站被加载,但只有在工具栏上的按钮被点击时引发此错误。如前所述,在SetSite函数被调用,然后IOleCommandTarget.Exec函数被调用。



所以,我想我的问题是:我怎么投传递到SetSite函数,这样我可以在选项卡上访问该文档对象的Internet Explorer当前?具有开放



有关这两个函数我目前的相关代码如下:

  INT IObjectWithSite.SetSite(对象的网站)
{
字符串显示=;

尝试{浏览器=(IWebBrowser2的)站点;}
赶上(例外五){显示+ = e.Message +\r\\\
}

System.Windows.Forms.MessageBox.Show(显示);

返回0;
}


INT IOleCommandTarget.Exec(IntPtr的pguidCmdGroup,UINT nCmdID,UINT nCmdexecopt,IntPtr的pvaIn,IntPtr的pvaOut)
{
如果(表= = NULL)
{
型=新SomeForm();
form.InputText =;
}
form.ShowDialog();
返回0;
}

提前

感谢。


解决方案

exec函数实际执行之前调用SetSite。为了解决这一点,仍然有exec函数可以访问有关浏览器时,SetSite信息和GetSite功能应该在不同的类,exec函数访问存在。


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:

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 '

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.

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?

My current relevant code for those two functions is as follows:

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

Thanks in advance.

解决方案

The Exec function calls SetSite before actually executing. In order to work around this and still have the Exec function be able to access information about the browser, the SetSite and GetSite functions should exist in a separate class that the Exec function accesses.

这篇关于互联网浏览器加载项工具栏按钮错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆