如何获取指向 的 IHTMLElement 指针托管 ActiveX 控件的标记

发布于 2024-09-30 21:44:53 字数 608 浏览 0 评论 0原文

我有一个由 FireBreath 框架 (http://firebreath.org) 生成的 ActiveX 控件。我需要获取对 的引用托管 C++ 插件的页面中的标记。

如果我使用 NPAPI,我将使用 NPNVPluginElementNPObject 常量和 NPN_GetValue。

因此,为了确保我说得清楚,请说我的页面中有以下内容:

我想要获得对插件的引用,就像使用 document.getElementById("testPlugin") 一样,但从为该 mimetype 插入的 activex 控件的 C++ 代码中除外。

请注意,将 id 作为

传入。对我来说这不是一个好的选择,但是如果有一种方法可以从 activex 控件内部获取 ID,则可能可行。

编辑:我正在考虑使用 getElementsByTagName 并尝试通过 DOM 找到它,但是很难区分同一插件的两个实例之间的区别。

I have an ActiveX control generated by the FireBreath framework (http://firebreath.org). I need to get a reference to the <object> tag in the page that hosts the plugin from C++.

If I were using NPAPI, I would use the NPNVPluginElementNPObject constant with NPN_GetValue.

so to make sure I am being clear, say I have the following in the page:

<object id="testPlugin" type="application/x-someplugin" width="100%" height="100%"></object>

I want to get a reference to the plugin like I would if I used document.getElementById("testPlugin"), except from within the C++ code of the activex control that is inserted for that mimetype.

Please note that passing the id in as a <param> is not a good option for me, but if there is a way to get the ID from inside the activex control that may work.

edit: I am considering using getElementsByTagName and trying to find it through the DOM, but it would be difficult to tell the difference between two instances of the same plugin.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

猥︴琐丶欲为 2024-10-07 21:44:53

感谢来自芬兰的 FireBreath 贡献者 jtojanen,我们终于找到了解决方案。

首先,COM 对象必须注册为“Apartment”,而不是“Single”(在注册表中)。否则,这是行不通的;似乎是 COM 中的一个错误。

然后在调用 SetClientSite 后的任何地方,您都可以执行以下操作:

CComQIPtr<IOleControlSite> site(m_spClientSite);
CComPtr<IDispatch> dispatch;
site->GetExtendedControl(&dispatch);
CComQIPtr<IHTMLElement2> htmlElement = dispatch;

希望这可以节省一些时间;我花了将近两年的时间才找到可以为我解答这个问题的人。

htmlElement 中的对象将是 包装你的插件的标签;因此,如果您对任何接口进行 queryInterface,它应该会成功,但它实际上可能不是您的对象,它可能是您对象的包装器。

Thanks to FireBreath contributor jtojanen from Finland, we finally have a solution.

The first thing is that the COM object must be registered as "Apartment", not "Single" (in the registry). Otherwise, this will not work; seems to be a bug in COM.

Then anywhere after SetClientSite is called, you can do the following:

CComQIPtr<IOleControlSite> site(m_spClientSite);
CComPtr<IDispatch> dispatch;
site->GetExtendedControl(&dispatch);
CComQIPtr<IHTMLElement2> htmlElement = dispatch;

Hope this saves someone some time; it's taken me almost 2 years to find someone who could answer this for me.

The object in htmlElement will be the <object> tag that wraps your plugin; so if you queryInterface for any of your interfaces, it should succeed, but it may not actually literally be your object, it will likely be a wrapper to your object.

瑶笙 2024-10-07 21:44:53

在 C# 中:

    public int SetSite(object site)
    {
        if (site != null)
        {
            var oleControl = (IOleControlSite)site;
            object oHtmlElement;
            oleControl.GetExtendedControl(out oHtmlElement);
            var htmlElement = (IHTMLElement2)oHtmlElement;
            ...
        }
    }

In C#:

    public int SetSite(object site)
    {
        if (site != null)
        {
            var oleControl = (IOleControlSite)site;
            object oHtmlElement;
            oleControl.GetExtendedControl(out oHtmlElement);
            var htmlElement = (IHTMLElement2)oHtmlElement;
            ...
        }
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文