Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API doesn't expose runtimeLib #40

Open
relf108 opened this issue Nov 26, 2020 · 2 comments
Open

API doesn't expose runtimeLib #40

relf108 opened this issue Nov 26, 2020 · 2 comments

Comments

@relf108
Copy link

relf108 commented Nov 26, 2020

I'm trying to manually call a global function and was expecting to be able to use dart-native's dynamic library runtimeLib. I've realized this is not exposed in the API and am wondering how I would access dart-native's dynamic library as is. My thoughts were DynamicLibrary.open('dart_native.framework/dart_native'); but I'm unsure as to whether I need to manually register a dealloc callback for the dynamic library in this scenario and whether my lib instance and yours would conflict.
below is all the code I'm using to access the global function. I should note, I'm getting syntax errors on this saying "Type given to lookup function must be a valid 'dart.ffi' native function type" despite CFURLRef doing nothing but extending a Struct
class CFURLRef extends Struct{}
It's my understanding Struct is a native type. Any thoughts as to what's going on here?

/// C function `CFURLCreateWithFileSystemPath`.
CFURLRef CFURLCreateWithFileSystemPath(
  CFAllocatorRef arg0,
  CFStringRef arg1,
  CFURLPathStyle arg2,
  bool arg3,
) {
  return _CFURLCreateWithFileSystemPath(arg0, arg1, arg2, arg3);
}

final _CFURLCreateWithFileSystemPath_Dart _CFURLCreateWithFileSystemPath =
    _dynamicLibrary.lookupFunction<_CFURLCreateWithFileSystemPath_C,
        _CFURLCreateWithFileSystemPath_Dart>(
  'CFURLCreateWithFileSystemPath',
);
typedef _CFURLCreateWithFileSystemPath_C = CFURLRef Function(
  CFAllocatorRef arg0,
  CFStringRef arg1,
  CFURLPathStyle arg2,
  bool arg3,
);
typedef _CFURLCreateWithFileSystemPath_Dart = CFURLRef Function(
  CFAllocatorRef arg0,
  CFStringRef arg1,
  CFURLPathStyle arg2,
  bool arg3,
);
@yulingtianxia
Copy link
Member

yulingtianxia commented Nov 26, 2020

DartNative doesn't support global C function for now, but you can call it using dart:ffi, here is the tutorial: https://dart.dev/guides/libraries/c-interop. The runtimeLib is private. You will create your native framework/library, it's not conflict with dart_native.framework.

When you pass an instance of NSObject or CGRect * to C function, you should pass its pointer.

@relf108
Copy link
Author

relf108 commented Nov 27, 2020

That clears everything up. Thanks very much for your help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants