Flutter FFI bridge for C# DLL

146 Views Asked by At

i'm using flutter desktop for my windows softwares, but i just bumped into ffi to make external dlls working.

If I make the library, i know i can use UnmanagedExport package to use the [DLLExport] notation and so flutter can use that method. But now i got some dll library for C# from a card reader, and i always get errors like: cannot find the symbol or not access pointer found.

I also tried to make a wrapper in C# embedding the external dll (using reference or DLLImport). But i got the same result: Exception: System.EntryPointNotFoundException: Can't find access pointer with name 'sum' inside 'ClassLibrary1.dll'. in FlutterBridge.originalFunct.sum(Int32 a, Int32 b)

(i translated the error from my main language).

Is there a way to use third party dll in flutter or to make wrapper/bridge to use them? Also i got the same problem with a 32bit dll, since flutter only wants 64bit libraries.

My code just attach something:

flutter:

const dll = 'FlutterBridge.dll';
DynamicLibrary library;
library = DynamicLibrary.open(dll);

final addPointer = library.lookup<NativeFunction<AddFunc>>('mysum');
final add = addPointer.asFunction<Add>();

final result = add(_counter, 2);

C#

public class originalFunct
{
    [DllImport("ClassLibrary1.dll")]
    public static extern Int32 sum(Int32 a, Int32 b);
}

public class Class1
{
    [DllExport]
    public static Int32 mysum(Int32 a, Int32 b)
    {
        return originalFunct.sum(a, b);
    }
}

Obviously "ClassLibrary1.dll" is another classic C# library without UnmanagedExport to emulate external libs. I don't have the source code of the card reader dll, but i have the same error i get with my test because flutter can't access to the pointer. Inside i have this code:

namespace ClassLibrary1
{
    public class SumClass
    {
        public static Int32 sum(Int32 a, Int32 b)
        {
            return a + b;
        }
    }
}

I hope i explained in a nice way.

Here a screenshot of FlutterBridge.dll entrypoint enter image description here

0

There are 0 best solutions below