要引入两个模块,两个是不同的:
dart
import 'dart:ffi';
import 'package:ffi/ffi.dart';
pointer char to string:
dart
var screenStr = (xx.GetSomeStrFun().cast<Utf8>().toDartString());
var s = screenStr.split("x");
_screenSize = {"width": double.parse(s[0]),"height":double.parse(s[1])};
print(_screenSize);
dart
//加载符号
DynamicLibrary nativeApi = Platform.isAndroid
? DynamicLibrary.open("libnative_ffi.so")
: DynamicLibrary.process();
//查找目标函数
FFI_greetingString greetingFunc = nativeApi
.lookupFunction<Native_greetingString, FFI_greetingString>("greetString");
//调用 greetString 函数,并将结果转为 Dart String.
Pointer<Int8> result = greetingFunc();
String greeting = result.cast<Utf8>().toDartString();
//打印结果
print("greeting=$greeting");
//输出结果
//greeting=Hello from Native