Skip to content

Latest commit

 

History

History
90 lines (69 loc) · 3.37 KB

README.md

File metadata and controls

90 lines (69 loc) · 3.37 KB

ci Package: winmd Publisher: halildurmus.dev Language: Dart License: BSD-3-Clause codecov

A package that provides a Dart language abstraction over Windows Metadata (WinMD) files, making it possible to load them and build Dart FFI interop libraries from the results.

It can be used to query Windows developer APIs, encompassing both unmanaged APIs like Win32 or COM, as well as modern APIs like Windows Runtime (WinRT) that include their own metadata.

Architecture

Architecture diagram

Usage

A simple example that loads the MessageBoxW function and prints out its parameters and return type:

import 'package:winmd/winmd.dart';

void main() async {
  // Load the Win32 metadata.
  final scope = await MetadataStore.loadWin32Scope();

  // Find a namespace.
  final namespace =
      scope.findTypeDef('Windows.Win32.UI.WindowsAndMessaging.Apis')!;

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

  // Find a specific function.
  const funcName = 'MessageBoxW';
  final method = sortedMethods.firstWhere((m) => m.name == 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) => '${param.typeIdentifier.name.split('.').last} ${param.name}',
      )
      .join(', ');
  print('The parameters are:\n  $params');

  final returnType = method.returnType.typeIdentifier.name.split('.').last;
  print('It returns type: $returnType.');

  MetadataStore.close();
}

More examples can be found in the example subdirectory.

Packages built on winmd

  • win32: provides Dart FFI bindings to the Win32 API, allowing you to call unmanaged Windows APIs using Dart types.

Feature requests and bugs

Please file feature requests and bugs at the issue tracker.