0

I'm trying to use the flutter ffi to port over my c/c++ code but it's unable to open the dynamic library it needs to be able to work(I'm on windows)

import 'dart:ffi';
import 'dart:io' show Directory, Platform;

import 'package:ffi/ffi.dart';
import 'package:path/path.dart' as path;

typedef ValidNative = Bool Function(Pointer<Utf8> name, Pointer<Utf8> password);
typedef valid = bool Function(Pointer<Utf8> name, Pointer<Utf8> password);

void main() {
  // Open the dynamic library
  var libraryPath = path.join(Directory.current.path, 'src', 'ye.so');
  if (Platform.isMacOS) {
    libraryPath = path.join(Directory.current.path, 'src', 'ye.dylib');
  }
  if (Platform.isWindows) {
    libraryPath = path.join(Directory.current.path, 'src', 'dll');
  }
  final dylib = DynamicLibrary.open(libraryPath);
  final valid Valid = dylib.lookupFunction<ValidNative, valid>('valid');

  var thi = Valid('Admin'.toNativeUtf8(), 'password'.toNativeUtf8());
}

does anyone know how I could fix this and get it to open the library(in my case the DLL file)? Any help would be appreciated!

edit_ here's some information the error code provided:

#0      _open (dart:ffi-patch/ffi_dynamic_library_patch.dart:12:43)
#1      new DynamicLibrary.open (dart:ffi-patch/ffi_dynamic_library_patch.dart:23:12)
#2      main (package:zenwall/ffi_bridge.dart:19:32)
#3      _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:297:19)        
#4      _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:192:12)
Nimantha
  • 6,405
  • 6
  • 28
  • 69
  • 1
    Except the title of your question, is there more to the error you are getting? – tomerpacific Apr 20 '22 at 05:57
  • Check that `libraryPath` matches the actual path of your dll. Check that the dll is compiled for 64 bit. – Richard Heap Apr 20 '22 at 10:16
  • @tomerpacific well it also says "error code 193" and I've included the rest of the error in an edit to the question – Paul Afriyie Apr 20 '22 at 22:30
  • @RichardHeap, You were right, my dll file wasn't compiled for 64 bit and there were some other things that went wrong in its making so now that I've fixed it works, thank you! – Paul Afriyie Apr 21 '22 at 06:28
  • @PaulAfriyie How do you fix this issue. I'm facing same issue dll file only generated under "build/windows/runner/Debug" and am not getting in under "build/windows/x64/Debug" – Gowtham Sooryaraj Jan 25 '23 at 14:06

0 Answers0