2
votes

I'm trying to call a native C/C++ void function form dart side via dart:ffi,

final Void Function(void) funcNativeStart =
nativeGuestLib
    .lookup<NativeFunction<Void Function(void)>>("NativeStart")
    .asFunction();

This gives me compiler error

The type 'Void Function(void)' must be a subtype of 'Void Function(void)' for 'asFunction'

I've played around with a few edits, such as

final Void Function() funcNativeStart =
nativeGuestLib
    .lookup<NativeFunction<Void Function()>>("NativeStart")
    .asFunction();
final Void Function(Void) funcNativeStart =
nativeGuestLib
    .lookup<NativeFunction<Void Function(Void)>>("NativeStart")
    .asFunction();

But the results are all similar to what I've got with the first version.

How to fix this?

1

1 Answers

3
votes

Solved it myself.

The working version should be

final void Function() funcNativeStart =
nativeGuestLib
    .lookup<NativeFunction<Void Function()>>("NativeStart")
    .asFunction();

The idea is that since we are "translating" native types into Dart (from right to left as for the equation), we should use the Dart language types on the left side of the equation, and the FFI native types on the right side.