'How to call a MFC Regular DLL in Dart or Flutter?

How could I call a MFC Regular DLL in Dart/Flutter?

I successfully called a pure (No MFC) C++ DLL. But when I pasted the same code into a new-created MFC regular DLL project, DART RUN gave me:

Invalid argument(s): Failed to lookup symbol 'hello_world': error code 127 ...

Below is my own code:

  • lib_mfc\pch.h:
    extern "C" _declspec(dllexport) void hello_world();
    
  • lib_mfc\pch.cpp
    void hello_world()
    {
        printf("[From C++:] Hello World\n");
    }
    
  • bin\ffi_sample.dart // it works well for a non-mfc dll
    final dylib = ffi.DynamicLibrary.open(libraryPath);
    final ffi.Pointer<T> Function<T extends ffi.NativeType>(String symbolName) _lookup = dylib.lookup;
    late final _hello_worldPtr = _lookup<ffi.NativeFunction<ffi.Void Function()>>('hello_world');
    late final _hello_world = _hello_worldPtr.asFunction<void Function()>();
    _hello_world();
    


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source