A package that wraps some of the most common Win32 API calls using FFI to make them accessible to Dart code without requiring a C compiler or the Windows SDK.

pub package Language

Perhaps of as much use as the APIs themselves, this package provides a variety of instructive examples for more complex FFI usage scenarios.

By design, this package provides minimal modifications to the Win32 API to support Dart idioms. The goal is to provide high familiarity to an existing Win32 developer. Other plugins may build on these primitives to provide a friendly API for Dart and Flutter developers. A good example of that is filepicker_windows, which offers a common item dialog suitable for incorporation into an existing Flutter app.

Requirements

This package assumes the Dart 32-bit or 64-bit compiler, running on Windows.

Usage

A simple Petzoldian Hello World example can be found in the example subdirectory. This example demonstrates creating a Win32 window and responding to common messages such as WM_PAINT through a WindowProc callback function.

To run it, type:

dart example\hello.dart

This should display a window with a text message.

This can be compiled into a standalone Win32 executable by running:

dart2native example\hello.dart -o example\bin\hello.exe

Samples

Dart samples

The package includes a number of examples in the example subdirectory. These examples use the Win32 API for all UI display and do not require Flutter.

ExampleDescription
hello.dartBasic Petzoldian "hello world" Win32 app
paint.dartDemonstrates simple GDI drawing and min/max window sizing
scroll.dartExample of horizontal and vertical scrolling text window
console.dartShows usage of console APIs
msgbox.dartDemonstrates a MessageBox from the console
calendar.dartGets information about the calendar from a WinRT API
sendinput.dartSends keyboard and mouse input to another window
knownfolder.dartRetrieves known folders from the current user profile
window.dartEnumerates open windows and basic window manipulation
monitor.dartUses DDC and monitor-config API to get monitor caps
wallpaper.dartShows what wallpaper and background color are set
guid.dartCreates a globally unique identifier (GUID)
devices.dartUses volume management APIs to list all disk devices
modules.dartEnumerates all loaded modules on the current system
snake.dartSnake game using various GDI features
dialogshow.dartCreates a common item dialog (file picker) using COM
wmi.dartUsing WMI from COM to retrieve device/OS information
sysinfo.dartExamples of getting device information from native C APIs
winmd.dartInterrogate Windows Runtime types
dynamic_load.dartDemonstrate loading a DLL and calling it at runtime
tetris\main.dartPort of an open-source Tetris game to Dart
notepad\notepad.dartLightweight replica of the Windows notepad applet

Flutter samples

The explorer\ subdirectory contains an example of a simple Flutter app that uses the volume management Win32 APIs to find the disk drives connected to your computer and their volume IDs and attached paths.

Features and bugs

Let me know what APIs you're interested in seeing. I'm not planning to project the entire Windows API, but I'm particularly interested in examples that either unblock a plugin for Windows or that demonstrate more complex Windows APIs that represent an important pattern.

Please file feature requests and bugs at the issue tracker. This is a hobby project, and should not be viewed as having the same level of quality assurance as an official package from the Dart team. I'm a product manager having fun on my weekends!

Acknowledgements

The Tetris example listed above is a fuller worked example of a reasonably complete program that uses the Dart Win32 package. It is a port of a C version of the game by Chang-Hung Liang. More information...

The C implementation of the Snake game is by David Jones, and is ported with his permission.

The original C version of the Notepad example was originally authored by Charles Petzold, and is kindly licensed by him without restriction.

Libraries

win32
Support for programming against the Win32 API on Windows operating systems. [...]