# 🚀node调用OCX
📅 2024/7/8
# 环境清单
所需环境与调用DLL所使用的环境一致。
# 安装winax
npm i winax
const winax = require('winax')
const Variant = winax.Variant
const shell = new winax.Object('wscript.shell')
const result = shell.Run(new Variant(path))
上述示例为通过shell 打开指定路径的程序,传递的参数需要使用new Variant进行加工。
# 注册/卸载 OCX
#注册OCX
regsvr32 [文件路径]
#卸载OCX
regsvr32 /u [文件路径]
# 打包问题
如果在pkg打包完成后运行出现:
NODE_MODULE_VERSION 64. This version of Node.js requires NODE_MODULE_VERSION 67. Please try re-compiling or re-installing the module (for instance, usingnpm rebuildornpm install).
这是由于编译的winax addon与pkg打包使用的node版本不兼容导致的,需要通过rebuild 或者 在相应版本下重新安装编译winax解决,为了防止这种情况,建议开发时使用的node版本与pkg打包使用的版本一致。