dllimport_gen 1.2.3

  • Readme
  • Changelog
  • Installing
  • 56

A code generation tool that aims to quickly generate dart code from the windows api documentation emulating the DllImport notation in C#.

Example:

import 'package:dllimport_gen/dll_import.dart';

import 'example.ffi.g.dart';

@DllImport('user32.dll')
abstract class User32 {
  /// https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setcursorpos
  BOOL SetCursorPos(int X, int Y);
}

@DllImport('kernel32.dll')
abstract class Kernel32 {
  /// https://docs.microsoft.com/en-us/windows/win32/api/errhandlingapi/nf-errhandlingapi-getlasterror
  DWORD GetLastError();
}

void main() {
  var user32 = FFIUser32();
  var kernel = FFIKernel32();
  var success = user32.SetCursorPos(0, 0) != 0;
  if (!success) {
    print('Failed: ${kernel.GetLastError()}');
  }
}

Run the code generation: pub run build_runner build

See example/


Use @Import('<library>') to import a custom library in the generated file, if for example you're using your custom structs.

1.0.0 #

  • Initial version, created by Stagehand

1.1.0 #

  • Use LibraryGenerator, Now you need to import the library instead of using the part directive.

1.2.0 #

  • Add @Import annotation.

1.2.1 #

  • Implement more types.

1.2.2 #

  • Fix possible symbol not found(127) error.

1.2.3 #

  • Add DynamicLibrary type for _dylib

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  dllimport_gen: ^1.2.3

2. Install it

You can install packages from the command line:

with pub:


$ pub get

Alternatively, your editor might support pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:dllimport_gen/annotations.dart';
import 'package:dllimport_gen/builder.dart';
import 'package:dllimport_gen/dll_import.dart';
import 'package:dllimport_gen/winapi_types.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
11
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
56
Learn more about scoring.

We analyzed this package on Jul 3, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.13

Analysis suggestions

Package not compatible with SDK flutter

Because it is not compatible with any of the supported runtimes: flutter-native, flutter-web

Package not compatible with runtime flutter-native on android

Because of the import of dart:mirrors via the import chain package:dllimport_gen/builder.dartpackage:dllimport_gen/src/dllimport_generator.dartpackage:source_gen/source_gen.dartpackage:source_gen/src/type_checker.dartdart:mirrors

Package not compatible with runtime flutter-native on ios

Because of the import of dart:mirrors via the import chain package:dllimport_gen/builder.dartpackage:dllimport_gen/src/dllimport_generator.dartpackage:source_gen/source_gen.dartpackage:source_gen/src/type_checker.dartdart:mirrors

Package not compatible with runtime flutter-native on linux

Because of the import of dart:mirrors via the import chain package:dllimport_gen/builder.dartpackage:dllimport_gen/src/dllimport_generator.dartpackage:source_gen/source_gen.dartpackage:source_gen/src/type_checker.dartdart:mirrors

Package not compatible with runtime flutter-native on macos

Because of the import of dart:mirrors via the import chain package:dllimport_gen/builder.dartpackage:dllimport_gen/src/dllimport_generator.dartpackage:source_gen/source_gen.dartpackage:source_gen/src/type_checker.dartdart:mirrors

Package not compatible with runtime flutter-native on windows

Because of the import of dart:mirrors via the import chain package:dllimport_gen/builder.dartpackage:dllimport_gen/src/dllimport_generator.dartpackage:source_gen/source_gen.dartpackage:source_gen/src/type_checker.dartdart:mirrors

Package not compatible with runtime flutter-web on web

Because of the import of dart:io via the import chain package:dllimport_gen/builder.dartpackage:dllimport_gen/src/dllimport_generator.dartpackage:source_gen/source_gen.dartpackage:source_gen/src/utils.dartpackage:build/build.dartpackage:build/src/generate/run_post_process_builder.dartpackage:build/src/builder/post_process_builder.dartpackage:build/src/builder/builder.dartpackage:build/src/builder/build_step.dartpackage:build/src/asset/reader.dartpackage:glob/glob.dartpackage:glob/src/list_tree.dartpackage:glob/src/io.dartpackage:glob/src/io_export.dartdart:io

Package not compatible with runtime native-aot

Because of the import of dart:mirrors via the import chain package:dllimport_gen/builder.dartpackage:dllimport_gen/src/dllimport_generator.dartpackage:source_gen/source_gen.dartpackage:source_gen/src/type_checker.dartdart:mirrors

Package not compatible with runtime web

Because of the import of dart:io via the import chain package:dllimport_gen/builder.dartpackage:dllimport_gen/src/dllimport_generator.dartpackage:source_gen/source_gen.dartpackage:source_gen/src/utils.dartpackage:build/build.dartpackage:build/src/generate/run_post_process_builder.dartpackage:build/src/builder/post_process_builder.dartpackage:build/src/builder/builder.dartpackage:build/src/builder/build_step.dartpackage:build/src/asset/reader.dartpackage:glob/glob.dartpackage:glob/src/list_tree.dartpackage:glob/src/io.dartpackage:glob/src/io_export.dartdart:io

Health suggestions

Format lib/winapi_types.dart.

Run dartfmt to format lib/winapi_types.dart.

Maintenance suggestions

Maintain an example.

None of the files in the package's example/ directory matches known example patterns.

Common filename patterns include main.dart, example.dart, and dllimport_gen.dart. Packages with multiple examples should provide example/README.md.

For more information see the pub package layout conventions.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.2.0 <3.0.0
analyzer ^0.39.8 0.39.11
build ^1.3.0 1.3.0
source_gen ^0.9.5 0.9.5
Transitive dependencies
_fe_analyzer_shared 5.0.0
args 1.6.0
async 2.4.1
charcode 1.1.3
collection 1.14.13
convert 2.1.1
crypto 2.1.5
csslib 0.16.1
dart_style 1.3.6
glob 1.2.0
html 0.14.0+3
js 0.6.2
logging 0.11.4
meta 1.1.8
node_interop 1.1.1
node_io 1.1.1
package_config 1.9.3
path 1.7.0
pedantic 1.9.0 1.9.1
pub_semver 1.4.4
source_span 1.7.0
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.2.0
watcher 0.9.7+15
yaml 2.2.1
Dev dependencies
effective_dart ^1.2.1