javascriptcfirefox-addonjsctypes

How to call native C code, using the js-ctypes Firefox extension?


I am trying to build a Firefox extension, that needs to call native C code.

My C program code is:

#include<windows.h>
int add(int a, int b)
{
    return(a + b);
}

and my JavaScript code is :

var {Cu} = require('chrome');
var self  = require('sdk/self');
Cu.import("resource://gre/modules/ctypes.jsm");
var lib;
var puts;
lib = ctypes.open('G:\\Shankar\\Project\\Maidsafe\\Firefox\\addon-sdk-1.17\\jsctype_sample\\data\\Win32Project1.dll');

try {
    puts = lib.declare("add", /* function name */
        ctypes.default_abi, /* call ABI */
        ctypes.int32_t, /* return type */
        ctypes.int32_t, /* argument type */
        ctypes.int32_t /* argument type */
    );
} catch (e) {
    console.log('Érror'+ e);
}

function binaryFile() {        
    var ret = puts(1, 2);
    dump(ret);
    lib.close();
};

exports.binaryFile = binaryFile;

when calling the binaryFile function, I get the error

Couldn't find function symbol in library

Please help me out. tHanks in advance.


Solution

  • Here is my repository where complete code is been available