Node.js调用C语言动态链接库依赖项和示例代码
依赖项
{
"name": "invoke-cpp-test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"rebuild": "./node_modules/.bin/electron-rebuild",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "liteng",
"license": "ISC",
"dependencies": {
"electron": "^8.5.5",
"electron-rebuild": "^1.10.0",
"ffi-napi": "^4.0.3",
"ref-array-napi": "^1.2.2",
"ref-napi": "^3.0.3",
"ref-struct-napi": "^1.1.1",
"ref-wchar-napi": "^1.0.3"
},
"devDependencies": {}
}示例代码
const path = require('path');
const ffi = require('ffi-napi');
const dll = path.resolve('./vcdll/elec_test.dll');
const lib = ffi.Library(dll, {
elec_add: ['int', ['int', 'int']]
});
console.log('1 + 2 = ' + lib.elec_add(1, 2)); 最后更新于1年前
本文由人工编写,AI优化,转载请注明原文地址: Node.js调用C语言动态链接库依赖项和示例代码
推荐阅读
评论 (0)
发表评论
昵称:加载中...
暂无评论,快来发表第一条评论吧!