This commit is contained in:
Sam 2018-10-07 14:03:14 -05:00 коммит произвёл GitHub
Родитель 178ed2b02e
Коммит 06b7d5ec0e
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
1 изменённых файлов: 2 добавлений и 2 удалений

Просмотреть файл

@ -89,11 +89,11 @@ MongoClient.connect(mongoUrl, function (err, db) {
## Accessing platform APIs
Sometimes you need to access plaform functionality for which no suitable module is available. For example your app may need to access the registry running on a Windows Server or Desktop. In this case there are 2 ways to proceed.
Sometimes you need to access platform functionality for which no suitable module is available. For example your app may need to access the registry running on a Windows Server or Desktop. In this case there are 2 ways to proceed.
1. Create a native module add-on by wrapping code in C binding boilerplate code [using the V8 sdk and dev tools](https://nodejs.org/api/addons.html).
2. Use [ref](https://github.com/TooTallNate/ref) and [node-ffi](https://github.com/node-ffi/node-ffi) modules to access C buffers and call shared library (DLL) functions from javascript.
There are plenty of examples of [creating native modules](http://www.martinchristen.ch/node/tutorial11), including our notes on [Compiling native addon modules](windows-environment.md#compiling-native-addon-modules) but less on [using ref and node-ffi](http://opendirective.net/blog/2015/10/working-with-windows-native-code-from-node-js). [NPM module for Windows Registry](https://github.com/CatalystCode/windows-registry-node) contains examples of how it leveraged [node-ffi](https://www.npmjs.com/package/ffi), [ref](https://www.npmjs.com/package/ref),[ref-struct](https://www.npmjs.com/package/ref-struct), [Advapi32.dll](https://msdn.microsoft.com/en-us/library/windows/desktop/ms724875(v=vs.85).aspx), and [Shell32.dll](https://msdn.microsoft.com/en-us/library/windows/desktop/bb762154(v=vs.85).aspx) to enable Node.js applications to communicate with Windows interfaces.
> :bulb: Note it is good practice to ensure published modules are written to run on all platforms (checkout writing cross platform modules and apps section in building-for-cross-platform.md), even though this can be conciderable extra work. Modules that only work on Windows or Linux are likely to unpopular so such code is best restricted to private modules or app code.
> :bulb: Note it is good practice to ensure published modules are written to run on all platforms (checkout writing cross platform modules and apps section in building-for-cross-platform.md), even though this can be considerable extra work. Modules that only work on Windows or Linux are likely to be unpopular so such code is best restricted to private modules or app code.