I am trying to call a C library from dart. The C code as a genertor method such as
a_struc create_struct(void);
and then methods that take in a pointer to struct, such as:
const char *
get_info(const a_struc * s);
I have created the dart binding using ffigen and I have
class a_struct extends ffi.Struct {
}
a_struct create_struct() {
return create_struct();
}
late final create_structPtr =
_lookup<ffi.NativeFunction<a_struct Function()>>(
'create_struct');
late final create_struct =
create_structPtr
.asFunction<a_struct Function()>();
and
ffi.Pointer<ffi.Int8> get_info(
ffi.Pointer<a_struct> a_struct,
) {
return get_info(
a_struct,
);
}
late final get_infoPtr = _lookup<
ffi.NativeFunction<
ffi.Pointer<ffi.Int8> Function(
ffi.Pointer<a_struct>)>>('rcl_publisher_get_topic_name');
late final get_info =
get_infoPtr.asFunction<
ffi.Pointer<ffi.Int8> Function(ffi.Pointer<a_struct>)>();
My problem is that I don't know how to call the method get_info
from the dart a_struct
generated by create_struct
. Indeed, get_info
expects a ffi.Pointer<a_struct>
but I only generate a a_struct
without the pointer. Since dart deprecated .addressOf
, how can I obtain a ffi.Pointer<a_struct>
from create_struct
?