winmd 0.4.0-dev.5 copy "winmd: ^0.4.0-dev.5" to clipboard
winmd: ^0.4.0-dev.5 copied to clipboard

outdated

A Dart library for working with Windows Metadata (winmd) formats.

This package provides a Dart abstraction over Windows metadata files, making it possible to load them and build Dart FFI interop libraries from the results.

pub package Language Code Coverage

Architecture #

Architecture diagram

Usage (Windows Runtime) #

A simple example: loading the IAsyncInfo interface and emitting the Dart equivalent file.

import 'package:winmd/winmd.dart';

final type = 'Windows.Foundation.IAsyncInfo';
final typeDef = MetadataStore.getMetadataForType(type);
final projection = TypeBuilder.projectWindowsType(typeDef);
final dartClass = TypePrinter.printType(projection);

final outputFilename = type.split('.').last;
final outputFile =
    File('${outputDirectory.uri.toFilePath()}$outputFilename.dart');

print('Writing:    ${outputFile.path}');
outputFile.writeAsStringSync(dartClass);

Usage (Win32) #

Load all the methods from the GDI namespace and print out some metadata.

import 'package:winmd/winmd.dart';

void main() {
  // Load WinMD metadata for Win32, as produced by the following utility:
  // https://github.com/microsoft/win32metadata
  final scope = MetadataStore.getScopeForFile('Windows.Win32.winmd');

  // Find the GDI API namesapce
  final gdiApi =
      scope.typeDefs.firstWhere((type) => type.typeName.endsWith('Gdi.Apis'));

  // Sort the functions alphabetically
  final sortedMethods = gdiApi.methods
    ..sort((a, b) => a.methodName.compareTo(b.methodName));

  // Find a specific function
  const funcName = 'AddFontResourceW';
  final method = sortedMethods.firstWhere((m) => m.methodName == funcName);

  // Print out some information about it
  print('This method is token #${method.token}');

  final params = method.parameters
      .map((param) => '${param.typeIdentifier.nativeType} ${param.name!}')
      .join(', ');
  print('The parameters are:\n$params');
}

Features and bugs #

Please file feature requests and bugs at the issue tracker.

9
likes
0
pub points
53%
popularity

Publisher

verified publisherhalildurmus.dev

A Dart library for working with Windows Metadata (winmd) formats.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

ffi, win32

More

Packages that depend on winmd