我想构建一个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