参考文档:ctypeshttp://udn.realityripple.com/docs/Mozilla/js-ctypes/js-ctypes_reference/ctypes
一、引用 ctypes.jsm方法
Components.utils.import("resource://gre/modules/ctypes.jsm")
二、用法
已知用法1: 结构体的声明ctypes.StructType()
(1)输入参数:结构体的名称、字段描述符。
(2)字段描述符定义:
每个描述符描述结构体中的一个字段。你可以不写字段描述符数组,这样会创建一个不透明结构体,其内容是未定义。
每个字段描述符 由 1个字段名和其数据类型组成,由1个字符串和1个CType对象表示。格式如下:
[
{ field1: type1 },
{ field2: type2 },
...
{ fieldN: typeN }
]
(3)例子
const mouseevent_t = ctypes.StructType(
"mouseevent_t",//结构体名称
//字段描述符:字段名:数据类型
[
{"button": ctypes.int},
{"clickCount": ctypes.int},
{"x": ctypes.long},
{"y": ctypes.long},
{"keys": ctypes.int},
]
);
已知用法2:函数声明 FunctionType
CType FunctionType(
abi,
returnType[,
argType1, ...]
);
(1)参数说明:
参数1:abi
ctypeshttp://udn.realityripple.com/docs/Mozilla/js-ctypes/js-ctypes_reference/ctypes#ABI%20constants
参数2:returnType
参数3:argType1... argTypeN
Return value:返回一个ctype
(2)例子:
const mouseevent_callback_t = ctypes.FunctionType(
ctypes.default_abi,
ctypes.void_t, // retval
[
handle_t, // handle
mouseevent_t.ptr, // event
]
).ptr;