winmd 0.4.12
winmd: ^0.4.12 copied to clipboard

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 Build

Architecture #

Architecture diagram

Usage (Windows Runtime) #

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

import 'package:winmd/winmd.dart';

void main() {
  // A Windows Runtime interface
  const type = 'Windows.Foundation.IAsyncInfo';

  // Load the metadata for this interface
  final typeDef = MetadataStore.getMetadataForType(type)!;

  // Project it into something Dart can work with
  final projection = ClassProjector(typeDef).projection;

  // Create a Dart projection
  final dartClass = TypePrinter.printType(projection);

  // Print it to the screen. Normally you'd save it to a file and format it.

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:
  final scope = MetadataStore.getWin32Scope();

  // Find a namesapce
  final namespace = scope['Windows.Win32.WindowsAndMessaging.Apis']!;

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

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

  // Print out some information about it
  print('Win32 function $funcName [token #${method.token}]');

  // Retrieve its parameters and project them into Dart FFI types
  final params = method.parameters
      .map((param) =>
          '${TypeProjector(param.typeIdentifier).nativeType} ${}')
      .join(', ');
  print('The parameters are:\n  $params');

  final returnType = TypeProjector(method.returnType.typeIdentifier).nativeType;
  print('It returns type: $returnType.');

Features and bugs #

Please file feature requests and bugs at the issue tracker.

pub points


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

Repository (GitHub)
View/report issues


API reference




ffi, win32


Packages that depend on winmd