我有C中的代码:
typedef result function_callback(struct mes_t* message, void* data)
struct mes_t
{
uint32_t field1
uint32_t field2
void* data
};
function_one(&function_callback, data)
应用程序调用用户定义的(在function_one中)回调函数function_callback。在回调函数中传递field1、field2和data参数(data通常等于0)
此示例的 python 代码是否正确编写?
class mes_t(ctypes.Structure):
pass
mes_t._fields_ = [
('field1', ctypes.c_uint32),
('dfield2', ctypes.c_uint32),
('data', ctypes.POINTER(ctypes.c_void_p))]
data_t=ctypes.c_void_p
data=data_t()
CALLBACK=CFUNCTYPE(ccg_msg, data_t)
cb_func=CALLBACK()
result = function_one(ctypes.byref(cb_func), ctypes.byref(data))