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 
目录
相关文章
|
15天前
|
前端开发 JavaScript 数据库连接
掌握 JavaScript 异步编程:从回调到 Async/Await
在现代 JavaScript 开发中,异步编程是处理非阻塞操作的关键技术。本文从早期的回调函数讲起,逐步过渡到 Promise 和 ES2017 的 async/await 语法,展示了异步编程如何变得更加简洁和强大。通过实用的技巧和最佳实践,帮助开发者避免常见陷阱,提升代码效率和可靠性。
|
1月前
|
JavaScript 前端开发 索引
JavaScript基础知识-数组基于索引访问
关于JavaScript数组基于索引访问的基础知识介绍。
16 1
JavaScript基础知识-数组基于索引访问
|
2月前
|
JSON JavaScript 前端开发
震惊!JS如何悄无声息追踪你的每一步?揭秘页面访问与关闭的超级上报大法,让数据说话,优化体验不再难!
【8月更文挑战第4天】在Web开发中,跟踪用户行为对提升体验与留存至关重要。本文以在线学习平台为例,介绍如何用JavaScript监听页面访问及关闭,并上报数据。通过`window.onload`监测页面加载,记录用户访问;利用`navigator.sendBeacon`在用户离开时发送少量数据至服务器,无需担心请求失败。需注意隐私合规、性能影响及浏览器兼容性。此技术有助于深入理解用户行为,为产品迭代提供依据。
72 8
|
2月前
|
Web App开发 JavaScript 前端开发
[译] 深入理解 Node.js 中的 Worker 线程
[译] 深入理解 Node.js 中的 Worker 线程
|
2月前
|
JavaScript 前端开发 API
揭秘Node.js如何轻松访问API:一个示例足以改变你的开发视角!
【8月更文挑战第21天】在现代Web开发中,API是软件间通信的关键。Node.js以其高效性,在API访问上独具优势。本文通过示例展示如何用Node.js访问API。首先确保已安装Node.js,然后使用npm安装`axios`库。创建`api_example.js`文件,并编写代码以访问JSONPlaceholder API获取数据。成功时,响应数据会输出至控制台;若失败,则打印错误。此示例展示了Node.js结合`axios`访问API的便捷性及高效性,为初学者提供快速入门指南。
26 0
|
3月前
|
前端开发 JavaScript
js 等待接口访问成功后执行指定代码【3种方法】(含async await Promise的使用)
js 等待接口访问成功后执行指定代码【3种方法】(含async await Promise的使用)
65 1
|
4月前
|
自然语言处理 JavaScript 前端开发
JavaScript闭包是函数访问外部作用域变量的能力体现,它用于封装私有变量、持久化状态、避免全局污染和处理异步操作。
【6月更文挑战第25天】JavaScript闭包是函数访问外部作用域变量的能力体现,它用于封装私有变量、持久化状态、避免全局污染和处理异步操作。闭包基于作用域链和垃圾回收机制,允许函数记住其定义时的环境。例如,`createCounter`函数返回的内部函数能访问并更新`count`,每次调用`counter()`计数器递增,展示了闭包维持状态的特性。
46 5
|
4月前
|
前端开发 JavaScript
JavaScript异步处理避免了单线程阻塞,如回调函数、Promise和async/await。
【6月更文挑战第22天】JavaScript异步处理避免了单线程阻塞,如回调函数、Promise和async/await。回调是基础,用于在操作完成后执行函数;Promise管理异步状态,支持链式调用;async/await提供同步代码外观,简化错误处理。每种技术在处理耗时任务时都起着关键作用。
36 3
|
4月前
|
前端开发 JavaScript 开发者
JavaScript中的异步操作与回调地狱解决方法
JavaScript中的异步操作与回调地狱解决方法 在现代的Web开发中,JavaScript扮演着极为重要的角色,尤其是在处理网络请求、文件操作或者任何可能耗费时间的操作时。为了不阻塞程序的执行,JavaScript 提供了异步编程模型。本文将介绍JavaScript中的异步操作是什么,什么是回调地狱,以及如何解决回调地狱问题。 什么是异步操作? 异步操作指的是那些不会立即完成的操作,程序可以在等待异步操作完成的同时,继续执行其他代码。JavaScript通常使用事件循环机制处理异步操作,这使得它可以在不阻塞主线程的情况下执行任务。 常见的异步操作包括: 网络请求(如使用 XMLHt
35 2
|
3月前
|
前端开发 JavaScript Linux
若依修改之后,无法访问前端项目如何解决,只能访问后端的接口,我的接口8083,端不显示咋解决?在vue.config.js文件中的映射路径要跟后端匹配,到软件商店里找到Ngnix配置代理,设80不用加
若依修改之后,无法访问前端项目如何解决,只能访问后端的接口,我的接口8083,端不显示咋解决?在vue.config.js文件中的映射路径要跟后端匹配,到软件商店里找到Ngnix配置代理,设80不用加