Accessing an SDK that is written in c++ using node.js

旧巷老猫 提交于 2020-01-13 11:15:18

问题


I have a SDK that will communicate with my Scanner device that is written in C++ language. I need to develop an Electron App that can access the Scanner device. I know there are many libraries available for scanner but I want to use this SDK since it will allow me to access full feature of the device and moreover it is provided by the device manufacturer. So, is there any way to implement this. Please suggest me any idea.


回答1:


You can use the native V8 API for that. You will need to provide a layer over your C++ code and expose it as Javascript entities.




回答2:


if there's also a C-style interface you could use node-ffi https://github.com/node-ffi/node-ffi




回答3:


If you're using electron 3 (which in turn uses Node 10), you can use N-API which has great examples on how to wrap a C++ object into a JS object. N-API is stable and supported by Node 10, so it's a pretty good choice over NaN and node-addon-api for the long term.

https://nodejs.org/api/n-api.html

Here's a repository of examples that proves pretty useful. This one specifically is for wrapping C++ objects. https://github.com/nodejs/abi-stable-node-addon-examples/tree/master/6_object_wrap/napi



来源:https://stackoverflow.com/questions/53653502/accessing-an-sdk-that-is-written-in-c-using-node-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!