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

2019-05-06 14:28发布

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.

3条回答
不美不萌又怎样
2楼-- · 2019-05-06 14:40

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.

查看更多
虎瘦雄心在
3楼-- · 2019-05-06 14:45

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

查看更多
Anthone
4楼-- · 2019-05-06 14:47

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

查看更多
登录 后发表回答