MFC Activex OCX Javascript 互相访问问题,线程回调javascript

简介: //比较好的教程    ocx 在 win7 系统会出现注册需要管理员权限的问题,这时候需要用管理员身份运行 cmd,然后运行 regsvr32注册。   很麻烦   尝试使用 nsis 做成安装包, 采用 regdll 注册 ocx, 成功。
//比较好的教程 
 
ocx 在 win7 系统会出现注册需要管理员权限的问题,这时候需要用管理员身份运行 cmd,然后运行 regsvr32注册。
 
很麻烦
 
尝试使用 nsis 做成安装包, 采用 regdll 注册 ocx, 成功。
 
 

ocx和外面的程序交互主要通过提供方法属性 + 事件

方法属性可以提供给js调用,

事件可以给js 通过下面的方式进行回调注入
<object id="xxx"></object>
<script language="JavaScript" for="xx" Event="eventFunction(x)"> 
alert(x);
</script> 
 
或者
document.getElementByIdx_x(xx).attachEvent("eventFunction",function(x,y){
alert(x);
});


这两种功能都可以在类视图里面选择  XXXCtrl,右键选择 add ,会出现 方法属性事件
按照wizard进行添加就好。

主要记录一下如果ocx创建了线程,想通过事件回调js的话,会出现问题。
这时候解决方法就是通过 PostMessage(WM_THREADFIREEVENT,(WPARAM)NULL,(LPARAM)NULL); 下面的看看应该懂了

//-------------------------
SAMPLE:   Firing   Events   From   a   Second   Thread   
    
  ---------------------------------------------------------------------   
  The   information   in   this   article   applies   to:   
    
    -   Microsoft   Visual   C++,   32-bit   Edition   versions   4.0,   4.1,   4.2   
  ---------------------------------------------------------------------   
    
  SUMMARY   
  =======   
    
  MFC   based   ActiveX   controls   typically   fire   their   events   from   the   same   thread   
  that   implements   the   sink   interface   of   the   container   that   the   events   are     
  being   fired   to.   
    
  Sometimes,   it   is   desirable   to   start   a   second   thread   in   an   ActiveX   control   
  which   will   fire   events   to   the   container.   Since   MFC   ActiveX   controls   
  use   the   Apartment   threading   model,   special   consideration   must   be   taken   
  into   account   when   firing   events   from   a   secondary   thread.   
    
  MORE   INFORMATION   
  ================   
    
  An   MFC   based   ActiveX   control   supports   events   by   implementing   the   
  IConnectionPointContainer   and   IConnectionPoint   interfaces,   as   well   as   
  supplying   information   about   it's   event   interface   in   it's   type   information.   
  When   an   MFC   based   ActiveX   control   is   embedded   in   a   container   that   supports   
  events,   that   container   will   dynamically   construct   a   sink   interface   that   has   
  all   of   the   methods   specified   in   the   control's   type   information   for   it's   
  event   interface.   Once   the   container   constructs   it's   sink   interface,   it   
  will   pass   a   pointer   to   that   interface   to   the   ActiveX   control.   The   ActiveX   
  control   will   use   it's   implementation   of   IConnectionPoint   to   communicate   
  through   the   now   hooked   up   sink   interface   that   was   constructed   by   the   
  container.   This   sample   will   demonstrate   how   to   call   methods   of   the   
  container's   sink   interface   from   a   second   thread.   
    
  The   two   most   important   things   to   consider   when   starting   a   new   thread   to   
  fire   events   from   in   an   ActiveX   control   are:   
    
  1.   MFC   based   ActiveX   controls   are   in-process   objects   (implemented   in   a     
        DLL).     
  2.   MFC   based   ActiveX   controls   use   the   Apartment   threading   model.   
    
  The   Apartment   threading   model   specifies   that   all   threads   that   want   to   use   
  OLE   services   must   initialize   OLE   in   their   thread   prior   to   using   OLE   
  services.   Also,   if   a   thread   wants   to   use   a   pointer   to   an   interface   that   is   
  either   implemented   by   a   different   thread   of   the   same   process   or   has   been   
  previously   marshaled   to   a   different   thread   of   the   same   process,   that   
  pointer   must   be   marshaled   to   the   requesting   thread.   In   the   Apartment   
  threading   model,   hidden   windows   are   created   to   synchronize   requests   from   
  other   threads   to   the   thread   being   called.   This   means   that   all   
  communication   between   threads   will   be   done   by   using   hidden   windows   and   
  Windows   messages   in   the   Apartment   model.   
    
  There   are   two   possible   ways   to   fire   events   from   a   second   thread   in   an   
  ActiveX   control   (or   any   other   in-proc   server   that   implements   connection   
  points)   under   the   Apartment   threading   model.   The   first   is   to   make   the   
  interface   call   from   the   second   thread   by   calling   the   event   sink's   method   
  from   the   second 
目录
相关文章
|
JavaScript API 开发者
在Vue.js中设置方法时访问$vuetify实例的正确姿势。
总之,访问 `$vuetify`实例是一种直观而有效的方法,它使得在Vue组件中处理Vuetify相关的逻辑成为可能。务必留意正确使用 `this`上下文,并确保在执行任何操作之前,Vue组件实例已经正确初始化并且可用。这种方式在组件自身逻辑与Vuetify的界面表现层之间架起了一座桥梁,使得开发者可以通过书写组件代码来控制和优化用户界面。
198 14
|
JavaScript 前端开发 算法
流量分发代码实战|学会用JS控制用户访问路径
流量分发工具(Traffic Distributor),又称跳转器或负载均衡器,可通过JavaScript按预设规则将用户随机引导至不同网站,适用于SEO优化、广告投放、A/B测试等场景。本文分享一段不到百行的JS代码,实现智能、隐蔽的流量控制,并附完整示例与算法解析。
539 1
|
前端开发 JavaScript 数据库连接
掌握 JavaScript 异步编程:从回调到 Async/Await
在现代 JavaScript 开发中,异步编程是处理非阻塞操作的关键技术。本文从早期的回调函数讲起,逐步过渡到 Promise 和 ES2017 的 async/await 语法,展示了异步编程如何变得更加简洁和强大。通过实用的技巧和最佳实践,帮助开发者避免常见陷阱,提升代码效率和可靠性。
|
前端开发 JavaScript
如何在 JavaScript 中访问和修改 CSS 变量?
【10月更文挑战第28天】通过以上方法,可以在JavaScript中灵活地访问和修改CSS变量,从而实现根据用户交互、页面状态等动态地改变页面样式,为网页添加更多的交互性和动态效果。在实际应用中,可以根据具体的需求和场景选择合适的方法来操作CSS变量。
814 12
|
JavaScript 前端开发 索引
JavaScript基础知识-数组基于索引访问
关于JavaScript数组基于索引访问的基础知识介绍。
208 1
JavaScript基础知识-数组基于索引访问
|
JavaScript 前端开发 开发者
掌握Node.js中的异步编程:从回调到async/await
Node.js的异步编程模型是其核心特性之一,它使得开发者能够构建高性能和高并发的应用程序。本文将带你从Node.js的异步编程基础开始,逐步深入到回调函数、Promises、以及最新的async/await语法。我们将探讨这些异步模式的原理、使用场景和最佳实践,并通过实例代码展示如何在实际项目中应用这些概念。
|
JSON JavaScript 前端开发
震惊!JS如何悄无声息追踪你的每一步?揭秘页面访问与关闭的超级上报大法,让数据说话,优化体验不再难!
【8月更文挑战第4天】在Web开发中,跟踪用户行为对提升体验与留存至关重要。本文以在线学习平台为例,介绍如何用JavaScript监听页面访问及关闭,并上报数据。通过`window.onload`监测页面加载,记录用户访问;利用`navigator.sendBeacon`在用户离开时发送少量数据至服务器,无需担心请求失败。需注意隐私合规、性能影响及浏览器兼容性。此技术有助于深入理解用户行为,为产品迭代提供依据。
716 8
|
前端开发 JavaScript UED
深入了解JavaScript异步编程:回调、Promise与async/await
【10月更文挑战第11天】深入了解JavaScript异步编程:回调、Promise与async/await
288 0
|
自然语言处理 JavaScript 前端开发
JavaScript闭包是函数访问外部作用域变量的能力体现,它用于封装私有变量、持久化状态、避免全局污染和处理异步操作。
【6月更文挑战第25天】JavaScript闭包是函数访问外部作用域变量的能力体现,它用于封装私有变量、持久化状态、避免全局污染和处理异步操作。闭包基于作用域链和垃圾回收机制,允许函数记住其定义时的环境。例如,`createCounter`函数返回的内部函数能访问并更新`count`,每次调用`counter()`计数器递增,展示了闭包维持状态的特性。
274 5
|
前端开发 JavaScript
js 等待接口访问成功后执行指定代码【3种方法】(含async await Promise的使用)
js 等待接口访问成功后执行指定代码【3种方法】(含async await Promise的使用)
1070 1

热门文章

最新文章