Search code examples
c++flutterdartflutter-desktopdart-ffi

Using a C++ DLL in Flutter The type must be a subtype


dll` to my flutter project

In .dll I type function:

int testdll(int param) {
//...
}

on flutter I type this:

final DynamicLibrary nativePointerTestLib = DynamicLibrary.open("assets/SimpleDllFlutter.dll");

final Int Function(Int arr) testdllflutter =
nativePointerTestLib
    .lookup<NativeFunction<Int Function(Int)>>("testdll")
    .asFunction();

and I get error

The type 'Int Function(Int)' must be a subtype of 'Int Function(Int)' for 'asFunction'. (Documentation) Int is defined in C:\flutter\bin\cache\pkg\sky_engine\lib\ffi\c_type.dart (c_type.dart:77). Int is defined in C:\flutter\bin\cache\pkg\sky_engine\lib\ffi\c_type.dart (c_type.dart:77). Try changing one or both of the type arguments.

Do you have any ideas?


Solution

  • I try call wrond types, correct types:

    final int Function(int arr) testdllflutter =
    nativePointerTestLib
        .lookup<NativeFunction<Int32 Function(Int32)>>("testdll")
        .asFunction();
    

    and it works