Call Windows API from node.js msg

You can also use this NPM package which already has (much of) the Win32 API entered (using ffi) and ready to use from NodeJS: https://github.com/waitingsong/node-win32-api


I didn't want to edit @Vadim's answer because it is accepted, but I think the package has been renamed to just 'ffi'. This worked for me:

npm install -s ffi

And using @Vadim's source but changing the package name to ffi:

var FFI = require('ffi');

function TEXT(text){
   return new Buffer(text, 'ucs2').toString('binary');
}

var user32 = new FFI.Library('user32', {
   'MessageBoxW': [
      'int32', [ 'int32', 'string', 'string', 'int32' ]
   ]
});

var OK_or_Cancel = user32.MessageBoxW(
   0, TEXT('I am Node.JS!'), TEXT('Hello, World!'), 1
);

I think node-ffi can help you to do that. node-ffi provides functionality for loading and calling dynamic libraries. With node-ffi you can get access to user32 (for example) lib and call their functions from node.js.

var FFI = require('node-ffi');

function TEXT(text){
   return new Buffer(text, 'ucs2').toString('binary');
}

var user32 = new FFI.Library('user32', {
   'MessageBoxW': [
      'int32', [ 'int32', 'string', 'string', 'int32' ]
   ]
});

var OK_or_Cancel = user32.MessageBoxW(
   0, TEXT('I am Node.JS!'), TEXT('Hello, World!'), 1
);