0

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?

Richard Heap
  • 48,344
  • 9
  • 130
  • 112
Nikolay
  • 344
  • 1
  • 15

2 Answers2

0

I try call wrond types, correct types:

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

and it works

Nikolay
  • 344
  • 1
  • 15
0

You are mixing up Dart integers (int) with C integers (IntXX). You are also using the old lookup, where the newer lookupFunction saves you some boilerplate.

Use this instead:

  final int Function(int param) testdllflutter = nativePointerTestLib
      .lookupFunction<Int32 Function(Int32), int Function(int)>('testdll');

testdllflutter is now a function taking one int returning int. The two types you need to pass to lookupFunction should be, first, the native-styled one, using native types that match the actual C integer sizes; then, second, the Dart-styled one, using Dart types. (The second one should match the type of the variable you are assigning it to.)

Richard Heap
  • 48,344
  • 9
  • 130
  • 112