如何获取IHTMLElement指针到< object>托管activex控件的标签 [英] How to get a IHTMLElement pointer to the <object> tag hosting an activex control

查看:435
本文介绍了如何获取IHTMLElement指针到< object>托管activex控件的标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个由FireBreath框架(http://firebreath.org)生成的ActiveX控件。我需要得到一个引用< object>



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



,以确保我清楚,说我在页面中有以下内容:



< object id =testPlugin type =application / x-somepluginwidth =100%height =100%>< / object>



如果我使用document.getElementById(testPlugin)插件,除非在为该mimetype插入的activex控件的C ++代码之内。



请请注意,将id作为< param>对我来说不是一个好的选择,但如果有一种方法可以从activex控件内部获得可能工作的ID。



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

解决方案



第一件事是COM对象必须

em>注册为公寓,而不是单一(在注册表中)。否则,这将不工作;



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

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

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



htmlElement中的对象将是< object>标签,它包装你的插件;所以如果你的任何接口的queryInterface,它应该成功,但它可能不是字面上实际上是你的对象,它可能是一个包装你的对象。


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.

解决方案

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.

这篇关于如何获取IHTMLElement指针到&lt; object&gt;托管activex控件的标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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