Giter Site home page Giter Site logo

nw_native_dll_sample's Introduction

Node-Webkit Sample with Native DLL

This is a sample app for node-webkit that calls a Native DLL.

node-webkit is a excellent framework for writing a cross platform GUI app. But there are some cases when you want to call a Native DLL.

You can use node-ffi to call Native DLLs from JavaScript. But the JS engine in node-webkit is V8 based and requires slightly different setup.

This is a minimum app showing how to call Native DLLs from JavaScript code in node-webkit.

  • Based on skelton code generated by generator-node-webkit.
  • Single set of source codes runs on Win/Mac and calls Native DLLs ( *.dylib, *.DLL )
  • Different sources for DLLs on each platform, with same API.

32bit issue

I'm not clear about this, but node-webkit ( at least some version ) requires DLLs to be 32bit version.

So, in this document, I recomend 32bit version of node.js.

usage

on Mac

test DLL with node.js cli

Install node.js 32bit version from Download page of nodejs.org .

Set NODE_PATH environmente variable.

$ export NODE_PATH=/usr/local/lib/node_modules

Install node-ffi and ref

$ npm install -g ffi
$ npm install -g ref

Compile sample1.dll and test it with node.js cli.

$ git clone https://github.com/essa/nw_native_dll_sample.git
$ cd nw_native_dll_sample
$ cd dlls/macosx
$ make
node ../test_sample.js
# If you see this message, the sample is working.
<Buffer@0x22591c0 05 00 00 00 01 00 00 00 6d 61 63 00 00 00 00 00 00 00 00 00 00 00 00 00>
{ sum: 5, difference: 1, platform: 'mac' }

You can see the sources at nw_native_dll_sample/dlls

Run the sample app with node-webkit

Install node-webkit and grunt-cli

$ npm install -g nodewebkit grunt-cli nw-gyp

Install ffi

$ grunt shell:install_ref shell:install_ffi

This task will compile a native module for node-webkit by commands like this.

$ rm -rf ffi
$ npm install ffi
$ cd node_modules/ffi
$ nw-gyp rebuild --target=0.8.5'

Modules made by nw-gyp is not compatible with node.js. If you want to run the sample with node.js cli, you must remove node_modules/ffi and node_modules/ref.

Run the app $ nodewebkit app

You will see this.

Screen Shot on Mac

The source is app/js/index.js

packaging

$ grunt dist-mac

You can copy dist/nw-dll-sample.app/ to other machine and run it.

on Windows

Install dependencies

You need to install these products to run this app.

test DLL with node.js cli

$ git clone https://github.com/essa/nw_native_dll_sample.git
$ cd nw_native_dll_sample
$ npm install ffi ref
$ cd nw_dll_sample/windows
$ make  
<Buffer@0x2a2fb98 05 00 00 00 01 00 00 00 77 69 6e 64 6f 77 73 00 00 00 00 00 00 00 00 00>
{ sum: 5, difference: 1, platform: 'windows' }

Run the sample app with node-webkit

$ npm install -g nodewebkit grunt-cli nw-gyp
$ grunt shell:install_ref shell:install_ffi
$ nodewebkit app

You will see this.

Screen Shot on Windows

The source is app/js/index.js

on Linux

(under construction)

create a skelton app source by yourself.

Install node-webkit and yeoman generator

$ npm install -g nodewebkit yo generator-node-webkit
$ yo node-webkit

Then copy Gruntfile.js, app/js/index.js, dlls/* from this repository and modify them.

nw_native_dll_sample's People

Contributors

essa avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.