简体   繁体   English

ActiveX加载方法的差异

[英]ActiveX Load Method Differences

I have a custom ActiveX control that is used by web pages in IE. 我有一个自定义ActiveX控件,供IE中的网页使用。 It loads just fine and is accessible to Javascript running in the page if I load it via an OBJECT tag like this: 如果我通过这样的OBJECT标签加载它,它就可以很好地加载并且可以在页面中运行的Java语言访问:

<object id="ccl" codeBase="ccl.cab" classid="CLSID:12372D58-F10C-11CF-B7A9-0020AFD6A362" NOEXTERNALDATA="true"></object>

But if I try to load it via new ActiveXObject() like this: 但是,如果我尝试通过新的ActiveXObject()加载它,如下所示:

var x = new ActiveXObject('myObj.abc');

I get the error "Automation server can't create object". 我收到错误“自动化服务器无法创建对象”。

I thought these two methods of loading a document were equivalent in the case where the ActiveX control has already been installed. 我认为在已经安装ActiveX控件的情况下,这两种加载文档的方法是等效的。 But apparently they're not. 但显然不是。 Can anyone help me understand under what conditions the OBJECT tag method would succeed while the new ActiveXObject method would fail? 谁能帮助我了解OBJECT标记方法在什么条件下会成功而新的ActiveXObject方法会失败? I have double-checked to make sure the progID I'm passing into new ActiveXObject() is correct and appears in the registry under HKEY_CLASSES_ROOT\\CLSID as it should. 我已仔细检查以确保我传递给新ActiveXObject()的progID是正确的,并应出现在注册表中的HKEY_CLASSES_ROOT \\ CLSID下。 Thanks in advance for any ideas. 预先感谢您的任何想法。

I can't find a supporting link but IE (at least older versions like 6 and 7) will not let you fire events from controls created with new ActiveXObject(). 我找不到支持的链接,但是IE(至少是6和7等较旧的版本)不允许您从使用新ActiveXObject()创建的控件中触发事件。 There may be other differences... internally in IE the code paths are very different. 可能还有其他差异...在IE内部,代码路径非常不同。 I don't know of a complete guide. 我不知道完整的指南。

You could set breakpoints in your SetSite() method and see if it's getting called. 您可以在SetSite()方法中设置断点,然后查看它是否被调用。 Also verify your registration is correct. 同时确认您的注册正确。

The startup for objects created in an object tag or an object created with ActiveXObject are different -- they would have to be, when you think about it, since one doesn't have a window to draw in. As is hinted here an object tag instantiates the control as a IObjectWithSite (by mshtml.dll), whereas new ActiveXObject instantiates it as an IOleObject (by jscript.dll). 在一个对象标签或ActiveXObject的创建的对象创建的对象的启动是不同的-他们必须是,当你想想看,因为一个没有窗户的绘制原样。 这里暗示一个对象标签将控件实例化为IObjectWithSite(由mshtml.dll来实现),而新的ActiveXObject将控件实例化为IOleObject(由jscript.dll来实现)。

This means that with ActiveXObject, SetSite is called and with an object tag SetClientSite is called . 这意味着使用ActiveXObject 会调用SetSite并使用对象标签SetClientSite来调用 Also, you will not get any IPersistPropertyBag calls, nor any InPlaceActivate, etc calls with ActiveXObject. 同样,您将不会通过ActiveXObject获得任何IPersistPropertyBag调用,也不会获得任何InPlaceActivate等调用。

It is of course possible to write a control to support both, as can be seen from the FireBreath source code I linked. 从我链接的FireBreath源代码可以看出,当然可以编写一个控件来支持两者。

A more complete explanation (from someone who understands it better) can be found here . 在这里可以找到更完整的解释(有更好的理解的人)。

Thanks to those who submitted the previous answers. 感谢那些提交先前答案的人。 While they didn't provide a solution to my problem, they set me on the right track to find the answer myself. 尽管他们没有为我的问题提供解决方案,但他们使我走上了正确的道路,以自己找到答案。

The problem was that my ActiveX control used the implementation of IObjectSafety provided by Microsoft's SiteLock template (IObjectSafetySiteLockImpl). 问题是我的ActiveX控件使用了Microsoft的SiteLock模板(IObjectSafetySiteLockImpl)提供的IObjectSafety的实现。 As the SiteLock documentation states: 正如SiteLock文档所述:

If you create an ActiveX control via script (instead of using the tag), then the scripting host is responsible for setting the site and not the browser. 如果通过脚本(而不是使用标签)创建ActiveX控件,则脚本编写主机负责设置站点,而不是浏览器。 Neither JavaScript nor the > VBScript engine will set the site until after it has decided that you are safe, so you cannot create a site-locked control that way. 在确定站点安全之前,JavaScript或> VBScript引擎都不会设置站点,因此您无法以这种方式创建站点锁定控件。

In this case my ActiveX control did not need the SiteLock functionality, so I replaced IObjectSafetySiteLockImpl with the standard ATL implementation of IObjectSafey (IObjectSafetyImpl). 在这种情况下,我的ActiveX控件不需要SiteLock功能,因此我用IObjectSafey的标准ATL实现(IObjectSafetyImpl)替换了IObjectSafetySiteLockImpl。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM