为Web浏览器实现ActiveX控件 [英] Implementing ActiveX Control for web browser

查看:281
本文介绍了为Web浏览器实现ActiveX控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的要求是开发一个ActiveX控件,该控件可以将字节流发送到串行端口. ActiveX控件应仅公开一个功能,如

My requirement is to develop a ActiveX control which can send the byte stream to serial port. The ActiveX control should expose only one function like

SendData(char* data, int nLen, int nPort)

应该可以通过按下Internet Explorer中渲染的Java开发的按钮(32位和64位)来调用此功能.我是否应该使用MFC/ATL或浏览器帮助器对象进行无窗口ActiveX控件感到困惑.将来我可能还需要支持Firefox.

This function should be able to be invoked by pressing a button developed in java rendered in Internet Explorer(both 32 and 64 bit). I am confused whether i should go with windowless ActiveX control using MFC/ATL or Browser Helper Objects. In future i may need to support Firefox also.

任何帮助将不胜感激.

推荐答案

尽管BHO可以工作,但ActiveX可以更好地满足您的要求. BHO与ActiveX非常相似-它们都是在浏览器窗口中运行的本机代码或托管代码.区别在于BHO适用于所有页面(在创建浏览器选项卡时实例化),而不是BHO的ActiveX在创建页面的某些Javascript代码(或带有< object>标记)时实例化. ActiveX的生命周期就是页面.

Although BHO would work, ActiveX will suite better your requirements. BHO are very similar to ActiveX - they are both native or managed code running in the browser window. The difference is that BHO is available for all pages (it is instantiated when the browser tab is created) while ActiveX which is not a BHO is instantiated when some Javascript code in the page creating it (or with the <object> tag. The life time of a ActiveX is the page.

ATL是更好的选择.使用VS向导,并创建一个基于ATL的COM进程内服务器.然后添加一个COM对象.由于您要从HTML调用它,因此请确保它是一个双重接口(即从IDispatch派生).将所需的方法添加到IDL文件.在COM中,字符串参数的调用约定为BSTR,而数组的标准约定为SAFEARRAY.您打算如何从Javascript代码中调用该方法?

ATL is a better choice. Use the VS Wizard, and create an ATL based COM in-proc server. Then add a COM object. Since you want to call it from HTML make sure it is a dual interface (i.e. derived from IDispatch). Add the method that you want to the IDL file. In COM, the calling convention for string arguments is BSTR, and the standard convention for array is SAFEARRAY. How do you plan calling the method from your Javascript code?

取决于您要如何从HTML页面实例化对象.您可以使用< object classid ='clsid:' class guid '>或者您可以使用Javascript:var myobj = new ActiveXObject( ProgId ).两种方法都有效.

Depends how you want to instantiate your object from the HTML page. You can have an <object classid='clsid:'class guid'> or you can use Javascript: var myobj = new ActiveXObject(ProgId). Both methods are valid.

这篇关于为Web浏览器实现ActiveX控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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