rbranson/node-ffi — Issue #34: Support different ABI on Windows
Author: Mithgol
Created: 2012-01-13 11:13:34+00:00
State: open

[`ffi.cc`](https://github.com/rbranson/node-ffi/blob/master/src/ffi.cc) does currently use `FFI_DEFAULT_ABI` (and `FFI_DEFAULT_ABI` only) when it calls `ffi_prep_cif(…)`.

That ABI, however, sometimes cannot be used for calling Windows system functions. I guess the following (very simple) code is an example of that:

```javascript
var user32 = new require('node-ffi').Library('user32', {
'MessageBoxW': [ 'int32', [ 'int32', 'string', 'string', 'int32' ]]
});

user32.MessageBoxW(0, 'Hello world!', 'Title of the window', 0);
```

When run, that example creates some dialog window, but the text (such as «Hello world!») is not readable:

![screenshot](http://i39.tinypic.com/209fukk.png)

Here node-ffi could follow Mozilla's [js-ctypes](https://developer.mozilla.org/en/js-ctypes/Using_js-ctypes) route and support a set of [ABI constants](https://developer.mozilla.org/en/js-ctypes/js-ctypes_reference/ctypes#ABI_constants) for an additional optional parameter of `require('node-ffi').Library(…)`. Probably in the same optional object (one object per function name) where `{async: 'true'}` may already be given.

The complete list of available ABI is defined in https://github.com/atgreen/libffi/blob/master/src/x86/ffitarget.h and similar platform-dependent files, but support for all of them would be complex and unnecessary. I beileve that node-ffi (like js-ctypes) does actually need only some two additional ABI necessary to call Windows system functions.