I have a windows c++ DLL. It provides some functions like add(1,2). But I don't have the source code for this DLL, is it possible call functions in this DLL through nodejs, I mean, through web side and http. If it possible, what should I do?
Asked
Active
Viewed 5.4k times
27
-
1Maybe you can find some useful infor from this question [http://stackoverflow.com/questions/9629677/how-can-i-use-a-c-library-from-node-js](http://stackoverflow.com/questions/9629677/how-can-i-use-a-c-library-from-node-js) – zangw May 27 '15 at 10:34
-
1Possible duplicate of [How can I use a C++ library from node.js?](http://stackoverflow.com/questions/9629677/how-can-i-use-a-c-library-from-node-js) – Software Engineer Feb 21 '17 at 09:49
2 Answers
4
Did you check out the ffi nodejs library? https://github.com/node-ffi/node-ffi
var ffi = require('ffi');
var libm = ffi.Library('libm', {
'ceil': [ 'double', [ 'double' ] ]
});
libm.ceil(1.5); // 2

Zsófi Ülkei
- 91
- 6
-
1
-
@Martian2049 could you explain why this isn't a good solution? It appears that this is a very popular library (15K weekly downloads). Could you elaborate on your comment? – Will Eccles Nov 12 '21 at 22:09
-
https://nodejs.org/api/addons.html @WillEccles check out this document if you haven't. it's more complicated approach but more reliable. – MartianMartian Nov 16 '21 at 05:17
-
-
2The addons system is for when you're writing your own C++ code for use with Node.js, which is kinda useless when you're a JS dev who knows zero C++ and you just need to work with a .dll file that someone gave you. Then you want something like node-ffi, which _is itself an addon_ specifically designed to act as a call proxy (and, as it should, comes with a warning that you're on your own and you better know what you're doing because segfaults are now on you ;) – Mike 'Pomax' Kamermans Oct 28 '22 at 22:38
-
(Do note that this is a very old project by now, of course, and the odds that it still works with your preferred version of Node are almost zero) – Mike 'Pomax' Kamermans Oct 28 '22 at 22:49
-
node-ffi is not maintained from 2019. It doesn't work in Windows, node v16.17.0, npm v8.15.0. Npm can not install node modules at all! – Dimitrios Ververidis Feb 01 '23 at 15:04
1
The https://github.com/node-ffi/node-ffi was indeed a good solution but not maintained since 2019.
The new version is:

Dimitrios Ververidis
- 1,118
- 1
- 9
- 33