title: Using a C++ DLL in Flutter Windows desktop app
body: <p>I have some libraries to interact with a FTDI chip that I packaged into a DLL in C++.
  I would like to create a front-end with Flutter and use that library in a windows desktop app.
  These features are still new in Flutter and the documentation is verry shallow and mobile specific.</p>
  <p>Following the guide <a href="https://flutter.dev/docs/development/platform-integration/c-interop" rel="noreferrer">here</a>, I created a plugin with FFI:</p>
  <pre><code>import 'dart:ffi';
  import 'dart:io';
  import 'dart:async';
  
  import 'package:flutter/services.dart';
  
  final DynamicLibrary FT232H = DynamicLibrary.open(&quot;&quot;);
  
  final int Function() initializeLibrary = FT232H
      .lookup&lt;NativeFunction&lt;Uint8 Function()&gt;&gt;(&quot;initialize_library&quot;)
      .asFunction();
  
  final void Function() cleanupLibrary = FT232H
      .lookup&lt;NativeFunction&lt;Void Function()&gt;&gt;(&quot;cleanup_library&quot;)
      .asFunction();
  
  final int Function() initializeI2C = FT232H
      .lookup&lt;NativeFunction&lt;Uint8 Function()&gt;&gt;(&quot;Initialize_I2C&quot;)
      .asFunction();
  
  final int Function() closeI2C = FT232H
      .lookup&lt;NativeFunction&lt;Uint8 Function()&gt;&gt;(&quot;Close_I2C&quot;)
      .asFunction();
  
  final int Function(
          Uint8 slaveAddress, Uint8 registerAddress, Uint32 data, Uint32 numBytes)
      i2cWriteBytes = FT232H
          .lookup&lt;NativeFunction&lt;Uint8 Function(Uint8, Uint8, Uint32, Uint32)&gt;&gt;(
              &quot;I2C_write_bytes&quot;)
          .asFunction();
  
  final int Function(Uint8 slaveAddress, Uint8 registerAddress,
          Uint8 bRegisterAddress, Pointer&lt;Uint8&gt; data, Uint32 numBytes)
      i2cReadBytes = FT232H
          .lookup&lt;
              NativeFunction&lt;
                  Uint8 Function(Uint8, Uint8, Uint8, Pointer&lt;Uint8&gt;,
                      Uint32)&gt;&gt;(&quot;I2C_read_bytes&quot;)
          .asFunction();
  
  class DllImport {
    static const MethodChannel _channel = const MethodChannel('dll_import');
  
    static Future&lt;String&gt; get platformVersion async {
      final String version = await _channel.invokeMethod('getPlatformVersion');
      return version;
    }
  }
  </code></pre>
  <p>And here is my header file on the other side:</p>
  <pre><code>#pragma once
  
  /* Include D2XX header*/
  #include &quot;ftd2xx.h&quot;
  
  /* Include libMPSSE headers */
  #include &quot;libMPSSE_i2c.h&quot;
  #include &quot;libMPSSE_spi.h&quot;
  
  #define FT232H_EXPORTS
  
  #ifdef FT232H_EXPORTS
  #define FT232H_API __declspec(dllexport)
  #else
  #define FT232H_API __declspec(dllimport)
  #endif
  
  
  extern &quot;C&quot; FT232H_API uint8 initialize_library();
  extern &quot;C&quot; FT232H_API void cleanup_library();
  extern &quot;C&quot; FT232H_API FT_STATUS Initialize_I2C();
  extern &quot;C&quot; FT232H_API FT_STATUS Close_I2C();
  extern &quot;C&quot; FT232H_API FT_STATUS I2C_write_bytes(uint8 slaveAddress, uint8 registerAddress, 
  const uint8 * data, uint32 numBytes);
  extern &quot;C&quot; FT232H_API FT_STATUS I2C_read_bytes(uint8 slaveAddress, uint8 registerAddress, 
  uint8 bRegisterAddress, uint8 * data, uint32 numBytes);
  </code></pre>
  <p>Here I am having some isses with the Uint8 pointers it seems as I am getting this error from my Dart code :</p>
  <pre><code>The type 'Uint8 Function(Uint8, Uint8, Uint8, Pointer&lt;Uint8&gt;, Uint32)' must be a subtype of 'int 
  Function(Uint8, Uint8, Uint8, Pointer&lt;Uint8&gt;, Uint32)' for 'asFunction'.
  Try changing one or both of the type arguments.dart(must_be_a_subtype)
  </code></pre>
  <p>Any pointers on how to make this happen in flutter would be greatly appreciated!</p>
  <p>Thank you.</p>