Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling C++ DLL in NodeJS asynchronous

I was create a web API with nodeJS and now I want to call C++ dll functions in it. The functions take a long while to executing (Complex image processing functions with openCV) and I want calling them in nodeJS async, many requests most process with this DLLs. how can I do that?

like image 579
pedramcode Avatar asked Sep 21 '26 13:09

pedramcode


1 Answers

You can use C++ Addons for this, a tutorial is in https://nodeaddons.com/calling-native-c-dlls-from-a-node-js-web-app/. It uses the node foreign function interface ( node-ffi ) to call code from .dll directly ( https://github.com/node-ffi/node-ffi/wiki/Node-FFI-Tutorial ). node-ffi basically provides wrapper functions for the functions in the dynamic library.

For the async requirement you can use Async Library Calls ability of node-ffi ( https://github.com/node-ffi/node-ffi/wiki/Node-FFI-Tutorial, chapter Async Library Calls ) or alternatively multiple processes like in How to create threads in nodejs

like image 137
ralf htp Avatar answered Sep 23 '26 01:09

ralf htp



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!