我想構建一個Firefox擴展,需要調用本地C代碼。如何使用js-ctypes Firefox擴展調用本地C代碼?
我的C程序代碼是:
#include<windows.h>
int add(int a, int b)
{
return(a + b);
}
和我的JavaScript代碼是:
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;
調用
binaryFile
功能時
,我得到的錯誤
Couldn't find function symbol in library
請幫我出。 tHanks提前。
不應該使用'int'而不是'int32_t'嗎? – meskobalazs 2015-02-09 13:43:01