visual studio 2010 - How to create a C++ COM object (with class factory) using ATL and VS2010 callable from Javascript - Stack O

I need to create a COM object which is callable from Javascript.I've been told that to do this,

I need to create a COM object which is callable from Javascript. I've been told that to do this, you need a COM object which also implements a class factory and it was suggested here that I try ATL. Someone pointed me to a Code Project ATL sample, however that doesn't cover the class factory.

I'm able to build a small ATL project with a simple object, but am unable to instantiate it, presumable because I haven't provided the class factory.

So, does anyone have experience building a simple COM object in VS2010 via ATL which can be called from Javascript?

EDIT: well, in reading the documentation for the DECLARE_CLASSFACTORY_EX it sounds like a default class factory IS provided. So now I'm not sure what's missing. What is needed to instantiate and invoke the class from Javascript?

EDIT: Also, to clarify, the Javascript where I'm calling the object from is in an HTML page being shown in the IE ActiveX control in an MFC dialog app. So that's the context in which the Javascript will run.

I need to create a COM object which is callable from Javascript. I've been told that to do this, you need a COM object which also implements a class factory and it was suggested here that I try ATL. Someone pointed me to a Code Project ATL sample, however that doesn't cover the class factory.

I'm able to build a small ATL project with a simple object, but am unable to instantiate it, presumable because I haven't provided the class factory.

So, does anyone have experience building a simple COM object in VS2010 via ATL which can be called from Javascript?

EDIT: well, in reading the documentation for the DECLARE_CLASSFACTORY_EX it sounds like a default class factory IS provided. So now I'm not sure what's missing. What is needed to instantiate and invoke the class from Javascript?

EDIT: Also, to clarify, the Javascript where I'm calling the object from is in an HTML page being shown in the IE ActiveX control in an MFC dialog app. So that's the context in which the Javascript will run.

Share Improve this question edited Nov 6, 2012 at 4:25 Nerdtron asked Nov 6, 2012 at 4:12 NerdtronNerdtron 1,5261 gold badge21 silver badges33 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 4

First of all, I believe you mean MS-specific JScript for Internet Explorer, because other browsers might not support COM/ActiveX.

You don't have to implement class-factory explicitly, because ATL framework already provides it. Just run ATL wizard: View --> Class view; in Class view right-click project root --> Add --> Class --> ATL Simple Object; set class name, and leave the defaults for all the rest. The wizard will define the following main things:

  1. Interface and co-class that implements it, in IDL file.
  2. C++ class, which would be the actual implementation of the above co-class. Pay attention to OBJECT_ENTRY_AUTO macro in the header file: it "connects" between your class and the ATL framework class-factory.
  3. *.rgs file, which is used to register your co-class in Windows registry.

Now you can add some methods to this newly created class - by means of wizard (right-click on class --> Add --> Add Function...), or manually.

Besides, in order to avoid security issues with your ponent, you have to implement IObjectSafety in your class: just inherit the c++ class from public IObjectSafetyImpl<CYourClass, INTERFACESAFE_FOR_UNTRUSTED_CALLER | INTERFACESAFE_FOR_UNTRUSTED_DATA>, and add COM_INTERFACE_ENTRY(IObjectSafety) to the interface map.

Now your class is ready for use from within JScript. In the script you can either create it statically, using object tag, or dynamically, using new ActiveX() statement. If your object has connection-points (i.e. fires events) and you don't want to be too tricky, you have to use the former approach.

I published sample code project earlier in response to another question: Exposing COM events to VBScript (ATL). It uses VBS and I assume JS conversion is an easy thing.

Code: SVN, Browser Friendly.

Another related sample: SVN, Browser Friendly + blog post explain things going on: Three ways to implement VBScript (VB6, VBA) callback from C++/ATL class.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745643760a4637848.html

相关推荐

  • 如何增加 Elasticsearch 中的主分片数量

    要增加现有索引的主分片数量,直接修改是不可能的。因此,如果你想增加主分片的数量,必须重新创建索引。通常有两种方法:_reindex API 和 _split API。在这两种方法中,_split API 通常比 _reindex API 更

    1小时前
    20
  • Kibana Alerting: 突破扩展性限制,实现50倍规模提升

    在过去的几年里,Kibana告警一直是许多大型组织的首选监控解决方案。随着使用的不断增加,用户创建的告警规则数量也在增长。越来越多的组织依赖Kibana进行大规模告警,我们看到了提高效率和确保未来工作负载性能的机会。在Kibana 8.16

    1小时前
    20
  • html制作一个放烟花动画的网页代码

    以下是一个用HTML制作的烟花动画网页代码,结合了粒子效果和重力模拟:html<!DOCTYPE html><html><head><title>烟花秀<title>

    1小时前
    20
  • 怎么用html写出哆啦A梦?

    用HTML和CSS来画哆啦A梦(Doraemon)是一项有趣且具有挑战性的任务。虽然HTML和CSS主要用于网页布局和样式,但通过巧妙的组合和定位,可以创建出相对简单的图形和图案。下面是一个简单的示例,展示了如何用HTML和CSS绘制哆啦A

    1小时前
    00
  • AI驱动的幼儿跌倒检测——视频安全系统的技术解析

    幼儿跌倒检测系统利用AI视频技术,结合人体姿态识别和实时报警功能,提供了一种智能化解决方案。本文将深入剖析其技术架构、模块实现与应用场景,探讨开源技术如何提升幼儿园安全管理。技术架构与实现项目背景幼儿在活动区域(如教室、操场)易发生跌倒,需

    1小时前
    00
  • MySQL 8.4 配置复制

    参考文档:.4enreplication-configuration.html1.先在源数据库主机的myf添加这几项代码语言:javascript代码运行次数:0运行复制[mysqld]server-id = 2binlog_forma

    1小时前
    00
  • MySQL8.4创建keyring给InnoDB表进行静态数据加密

    参考文档:.4enkeyring-plugin-installation.html.4enkeyring-hashicorp-plugin.html#keyring-hashicorp-vault-configuration1.首先

    1小时前
    10
  • MySQL8使用物理文件恢复MyISAM表测试

    我们现场测试一个场景,drop一张MyISAM表后,单独对这表进行物理恢复首先我们看一下secure_file_priv文件目录的位置代码语言:javascript代码运行次数:0运行复制mysql> show global vari

    1小时前
    00
  • AI生态暗战升级,科技巨头铁幕下的终极博弈

    一场围绕AI与智能体的标准、协议及生态的暗战已然蓄势待发。在美剧《权力的游戏》中,不到终局,主角归属始终成谜。如今的AI行业,正上演着同样扣人心弦的戏码。这并非是传统意义上的军事或政治博弈,而是一场围绕AI与智能体的标准、协议及生态展开的暗

    1小时前
    00
  • Go项目实战

    上节课我给大家介绍了怎么给Go项目做单元测试的规划,当然这里仅限于跟咱们课程里的实战项目一样分层架构设计做的还可以的项目哦,要是所有逻辑都耦合在Controller里,那这个规划就不适用了。。。,所有逻辑都耦合在Controller里还做个

    1小时前
    00
  • 取消Win10开机系统选择倒计时,让电脑秒进系统

    取消Win10开机系统选择倒计时,让电脑秒进系统 近期,不少Win10用户反映在开机时会遇到一个选择系统的倒计时画面,这在一定程度上延缓了开机进程。对于追求高效启动体验的用户来说,这无疑是一个不必要的步骤。那么,如何取消这个倒计时,让电脑

    1小时前
    00
  • 2025年最受欢迎的10款免费CRM软件大对比

    在数字化转型浪潮下,越来越多的企业开始重视客户关系管理(CRM)系统。一个高效的CRM不仅能帮助企业理清客户脉络,还能提升销售效率、优化服务体验。2025年,市场上涌现了众多优秀的免费CRM软件,本文将为大家对比10款最受欢迎的产品,助您选

    1小时前
    00
  • PackML over OPC UA

    在当今数字化转型的浪潮中,制造业正面临着前所未有的挑战与机遇。如何实现设备之间的高效通信与集成,成为提升生产效率、降低成本的关键。OPC UA(OPC Unified Architecture)与PackML(Packaging Machi

    58分钟前
    00
  • 1.8w字图解Java并发容器: CHM、ConcurrentLinkedQueue、7 种阻塞队列的使用场景和原理

    文章多图且内容硬核,建议大家收藏上一章《1.6w 字图解 Java 并发:多线程挑战、线程状态和通信、死锁;AQS、ReentrantLock、Condition 使用和原理》,我们开启了 Java 高并发系列的学习,透彻理解 Java 并

    55分钟前
    00
  • 我用AI监控了奥特曼,当他一发推特AI就会自动给我打电话。

    上周我真的扛不住了。奥特曼这个孙贼,发了个X说,“要发一个礼拜的好东西”。我信了他的邪,明明出差1周,每天早上9点不到就要起来参加活动,但是晚上根本不敢睡觉,天天蹲到凌晨3点半,蹲到他们那边时间中午12点多,我才敢去睡觉。真的,那一整周,我

    48分钟前
    00
  • 国产之光!!让你的Docker管理更优雅!

    大家好,我是热爱开源的了不起!我们都知道,Docker是个好东西,能帮我们把应用打包成容器,方便部署和管理。但问题来了,Docker的命令行操作对新手来说有点复杂,一不小心就容易出错。而且,有时候我们只是想简单地管理一下容器,却得记住一堆命

    46分钟前
    00
  • Prometheus配置docker采集器

    Prometheus 配置 Docker 采集器Prometheus 是一个开源的监控系统和时间序列数据库,广泛用于容器化环境中。通过监控 Docker 容器,用户可以实时获取服务性能、资源使用情况等信息。本文将介绍如何为 Docker 容

    30分钟前
    00
  • 什么是docker?它是如何工作的?

    想象一个场景,你要部署一个服务,然后它对环境有很多依赖,不同的操作系统又是不同的需求,而且还可能遇到有些源不能使用,又得一番折腾,折腾完上线后,假设要在新的环境再来一套,又得再来一遍。那么有没有什么办法可以解决呢?有办法,docker就是干

    15分钟前
    00
  • 人工智能与ai有什么区别

    一、引言:概念之辨的必要性在科技浪潮席卷全球的当下,人工智能(Artificial Intelligence,简称AI)已成为人们耳熟能详的词汇。然而,当我们深入探讨时,会发现“人工智能”与“AI”这两个表述在语义和使用场景上存在微妙差异。

    3分钟前
    00
  • 在VMware虚拟机中安装Windows 7全攻略(避坑指南)

    ⚠️写在前面 最近发现很多开发者在调试老旧系统时都需要用到Windows 7环境&#xff08;特别是银行、医疗等行业的遗留系统&#xff09;&#xff0c;但实体机安装既不现实也不安全。今天就手把手教你在虚拟机

    1分钟前
    00

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信