我目前在c#中开发IE工具栏按钮,该按钮应该能够获取当前选项卡的内容并使用它。但是,每当单击按钮时,调用IObjectWithSite.SetSite函数(我的代码将在末尾发布)并返回以下错误:

无法投射COM类型的对象 “系统.__ comobject”接口类型 shdocvw.iwebbrowser2'。这个操作 因为QueryInterface呼叫而失败 在COM ComponeNet上 与IID接口 '

函数在加载网站时正常工作,但只有在单击工具栏中的按钮时才会抛出此错误。如前所述,Setteite函数被称为,然后调用IoLecommandTarget.exec函数。

所以,我猜我的问题是:我将传递到Setteite函数的对象是什么,以便我可以访问Internet Explorer当前已打开的标签上的文档?

这两个函数的当前相关代码如下:

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

提前感谢。

有帮助吗?

解决方案 2

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.

其他提示

记录方式从工具栏按钮站点查询iWebBrowser2是从站点查询IserviceProvider,然后查询IID_IWebbrowserApp

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top