如何创建可在 Javascript 引擎中使用的 ActiveX
您是否知道创建可在 JScript 或 VBScript(基于 Windows 脚本的主机)中使用的 MFC ActiveX 对象的教程?
我的意思是OCX可以用作:
var x= new ActiveXObject("name");
并且不这个:
<object id="xxx" classid="CLSID:xxxx">
到目前为止,我发现的所有内容都只允许使用带有html标签的activex,并且它们无法使用脚本引擎进行初始化。
Do you know any tutorial for creating MFC ActiveX objects that can be used in JScript or VBScript (Windows Script Based Host)?
I mean an OCX that can be used as:
var x= new ActiveXObject("name");
and NOT this:
<object id="xxx" classid="CLSID:xxxx">
so far everything that I found just allow using an activex with html tags and they fail to initialize with script engine.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

发布评论
评论(3)
述情2025-01-01 00:42:52
就入门而言,我强烈建议您查看 编写简单 COM/ATL DLL 并将其与 .NET 一起使用的入门教程 作者:就是这样。
我尝试了多种不同的技术来创建 ActiveX 对象,并且我发现 ATL C++ 是我最喜欢的技术之一。本教程的关键要点是:
- 利用 Visual Studio ATL 简单对象向导
- 用 C++ 命名接口(例如
ISimpleCom
) - 选择 progid(例如
SimpleATLcom.SimpleCom
) - 让 Visual Studio为您生成尽可能多的代码
- 注册您的 COM DLL
本教程未涵盖的一些内容是:
- 避免 项目构建错误 PRJ0050 通过使用 Visual Studio 的每用户重定向注册 COM DLL 2008 支持(请参阅 Microsoft MSDN 文章 链接器属性页)
- 从 Windows 脚本宿主/HTML 中调用 JScript/VBScript
后者,您已经知道如何执行此操作,但是为了完整起见。在 JScript 中,它是:
var obj = new ActiveXObject("SimpleATLcom.SimpleCom");
在 VBScript 中,它是:
Dim obj
Set obj = CreateObject("SimpleATLcom.SimpleCom")
~没有更多了~
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
只是添加一些额外的选项:
1. 旧的 vb6 擅长非常简单地创建 ActiveX/COM 组件。
2. 其他语言如Delphi和PowerBasic也可以轻松创建组件。
3. VBScript 可用于创建封装在 com 包装器 WSC(Windows 脚本组件)中的 com 组件。它包含您的类和代码,并且可用作 COM 对象。当通过 COM 调用时,WSC 使用外部脚本组件运行时来执行脚本。实际的内部代码可以用其他脚本语言编写,例如 jscript 或 python 或许多其他语言。
Just to add some extra options:
1. Old vb6 was adept at creating ActiveX/COM components quite simply.
2. Other languages like Delphi and PowerBasic can easily create components too.
3. VBScript can be used to create com components which are packaged in a com wrapper WSC (Windows Script Component). This contains your class and code and is usable as a COM object. The WSC uses an external Script Component Runtime to execute your script when called via COM. The actual internal code can be written in other script languages, such as jscript or python or a number of others.