美文网首页
FFI 基础注册

FFI 基础注册

作者: CentForever | 来源:发表于2020-12-29 19:15 被阅读0次

    C++ 层初始化

    // Initialize `dart_api_dl.h`
    DART_EXPORT intptr_t InitDartApiDL(void* data) {
      return Dart_InitializeApiDL(data);
    }
    
    DART_EXPORT void RegisterSendPort(Dart_Port send_port) {
      send_port_ = send_port;
    }
    

    Dart 层初始化

    void doDynamicLinking() {
      Expect.isTrue(NativeApi.majorVersion == 2);
      Expect.isTrue(NativeApi.minorVersion >= 0);
      final initializeApi = testLibrary.lookupFunction<
          IntPtr Function(Pointer<Void>),
          int Function(Pointer<Void>)>("InitDartApiDL");
      Expect.isTrue(initializeApi(NativeApi.initializeApiDLData) == 0);
    }
    
      final initializeApi = dl.lookupFunction<IntPtr Function(Pointer<Void>),
          int Function(Pointer<Void>)>("InitDartApiDL");
      Expect.isTrue(initializeApi(NativeApi.initializeApiDLData) == 0);
    
      final interactiveCppRequests = ReceivePort()..listen(handleCppRequests);
      final int nativePort = interactiveCppRequests.sendPort.nativePort;
      registerSendPort(nativePort);
    
    final registerSendPort = dl.lookupFunction<Void Function(Int64 sendPort),
        void Function(int sendPort)>('RegisterSendPort');
    

    https://github.com/archanpaul/medium-flutter_with_go/issues/3

    使用

    const bool result = Dart_PostCObject_DL(send_port, &dart_object);
      if (!result) {
        FATAL("C   :  Posting message to port failed.");
      }
    

    相关文章

      网友评论

          本文标题:FFI 基础注册

          本文链接:https://www.haomeiwen.com/subject/acrtoktx.html