Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert Dart String to dartffi Pointer<Int8>

I used ffigen to generate bindings from a C header file. One of the methods in C is open(const char *path), and ffigen generated a binding method open(ffi.Pointer<ffi.Int8> path). If I want to have a dart method open(String path) that access this binding method how can I convert the String parameter to ffi.Pointer<ffi.Int8>?

like image 469
J. Gatica Avatar asked Oct 29 '25 06:10

J. Gatica


1 Answers

Try

"Your message".toNativeUtf8().cast<Int8>()

Also see erjo's comment in https://github.com/dart-lang/ffigen/issues/72

like image 172
tofutim Avatar answered Oct 31 '25 00:10

tofutim



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!