• Stars
    star
    633
  • Rank 68,835 (Top 2 %)
  • Language
    Dart
  • License
    BSD 3-Clause "New...
  • Created about 4 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Build Win32 apps with Dart!

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. Part of the Dart | Windows suite of Windows packages.

pub package package publisher Language Build

Documentation

Usage

This package lets you write apps that use the Windows API directly from Dart, by wrapping common Win32 and COM APIs using Dart FFI.

You could use it to call a Win32 API like EnumFontFamiliesEx to enumerate all locally-installed fonts:

Fonts screenshot

or access system information that is not exposed directly by the Dart framework libraries:

System information screenshot

You could use it to build a Windows app with Flutter that relies on Win32 APIs:

Disk explorer screenshot

You could even use it to build a traditional Win32 app, written purely in Dart, that could have come straight out of a classic Charles Petzold book on programming Windows apps:

Dart notepad screenshot

or even, perhaps, a fully-fledged game using GDI:

Dart Tetris for Win32 screenshot

You might even build a package that depends upon it, like dart_console, which enables advanced console manipulation:

Dart console ANSI color demo screenshot

or filepicker_windows, which provides a modern Windows file picker for Flutter:

Windows file picker screenshot

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 Windows developer. Other Dart packages may build on these primitives to provide a friendly API for Dart and Flutter developers. A good example of that is win32_registry, which offers a set of APIs for accessing the Windows registry that don't require knowledge of FFI.

Getting started

Many more samples can be found in the example\ subdirectory, along with a test suite in the test\ subdirectory that shows other API calls.

A good starting point is hello.dart. 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:

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

For more information on working with the Win32 library from Dart, consult the documentation.

Examples

There are many examples included with this package that demonstrate calling various Win32 and COM APIs. These can be found in the example\ folder; a short description of each example can be found here.

Packages built on win32

There are a growing number of packages that build on the relatively low-level APIs exposed by the Dart win32 package to provide more idiomatic class wrappers. These packages typically don't require any knowledge of Windows programming models or FFI, and are ideal for incorporation into Flutter apps for Windows.

A full list of these packages can be found on pub, and other packages from the Dart | Windows authors can be found here: https://github.com/dart-windows

  • filepicker_windows: makes the Windows file open / save common dialog boxes available to Flutter and Dart apps.
  • path_provider_windows: provides a way for Dart apps to find common Windows file locations (such as the documents directory).
  • win32_registry: provides Dart classes for accessing and manipulating the Windows registry.
  • win32_runner: provides an experimental shell (or runner) for hosting Flutter apps without needing a C++ compiler to create the EXE.

Requirements

This package is designed to run on 64-bit editions of Windows. The primary target is Intel processors, but the package is also tested on ARM architecture, running in x64 emulation mode.

Features and bugs

The current package only projects a subset of the Win32 API, but new APIs will be added based on user demand, particularly if it unblocks the creation of new Dart packages for Windows. Please file feature requests and bugs at the issue tracker.

Backwards compatibility

The library version models semver, but you cannot assume a strict guarantee of no breaking changes between minor versions. That guarantee is not possible to make, for several reasons:

  • The package is based on metadata published by Microsoft, which is generated by scraping Win32 SDK header files. As the quality of the scraper improves, there may be minor changes to some fields (for example, an unsigned integer may become a signed integer).
  • Adding new APIs may itself cause a breaking change. For example, if you declare a missing Windows constant in your own code that is then added, Dart will complain about the duplicate definition.

If this causes you concern, our recommendation is to pin to a specific version of Win32. But the best approach is simply to test regularly with the latest version of this package, and continue to move your minimum forward.

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 Snake is by David Jones, and is ported with his permission.

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

The original C version of the custom title bar example is by Dmitriy Kubyshkin and is licensed by him under the MIT License.

The summary Win32 API documentation comments are licensed by Microsoft under the Creative Commons Attribution 4.0 International Public License.

More Repositories

1

dart_console

Dart library for writing console applications
Dart
255
star
2

github-tracker

Grabs some useful information from GitHub.
Dart
102
star
3

filepicker_windows

Dart
58
star
4

win32_runner

Run a Flutter app without needing a lick of C/C++ code. Just Dart!
Dart
52
star
5

dadjokes

Awful dad jokes, curated for your pleasure
C++
43
star
6

time

Startup time for various languages
Shell
36
star
7

vs-clone

Clone a Visual Studio 2017 installation so it can be reproduced on another machine.
C#
23
star
8

winmd

A Dart package for extracting API metadata from Windows Metadata (.winmd) files.
Dart
21
star
9

win32_registry

Dart APIs for the Windows Registry
Dart
21
star
10

barcoder

A holiday hacking project. A book catalog management app. A Flutter sample. A waste of your time. All of these are likely true.
Dart
18
star
11

win32_gamepad

Dart
15
star
12

dart_kilo

Simple Dart-based text editor.
Dart
13
star
13

Gists

This is a simple Visual Studio extension that supports publishing a text selection or file to a GitHub Gist.
C#
13
star
14

slideplayer

Dart
13
star
15

advent-of-code-2022

My playground for Advent of Code 2022
Dart
10
star
16

notepad2

Updated version of Florian Balmer's free Notepad2 replacement.
C++
10
star
17

Notepad3

WPF-based Notepad clone, written to exercise the AvalonEdit text editor component
C#
8
star
18

advent-of-code-2021

My playground for Advent of Code 2021.
Dart
7
star
19

typography

A simple example of Flutter typography
Dart
7
star
20

ffi_demos

Some demonstrations of FFI code as presented at Flutter Vikings 2022
C
7
star
21

acrylic

C++
7
star
22

regedit

Dart
6
star
23

landmarks_flutter

Dart
6
star
24

VSIconOverlay

Small Visual Studio extension that adds an icon overlay with the current version.
C#
6
star
25

device_info_windows

Simple package that demonstrates calling WMI from Dart
C++
6
star
26

aqueduct3-heroes

Dart
5
star
27

windows_devices

Dart
3
star
28

itinerary

Dart
3
star
29

ffigen_com

Dart
3
star
30

wordcloud_flutter

A fun script to generate a Flutter-logo wordcloud
Python
3
star
31

dotfiles

Shell
2
star
32

z80

Dart
2
star
33

zxspectrum

Dart
2
star
34

pub_metadata

Dart
2
star
35

asia_trip

Dart
1
star
36

RLangService

Experimental support for the R language in Visual Studio
C#
1
star
37

cupabox

Dart
1
star
38

dart-playground

My personal playground for exploring the Dart programming language
Dart
1
star
39

r-github-stars

Plotting Github Star History
R
1
star
40

udemy_flutter

Flutter implementation of the London App Brewery iOS exercises
Dart
1
star
41

fooderlich

Dart
1
star
42

ExtensibilityDemos

Various Visual Studio extensibility demos
C#
1
star
43

windowshook

C++
1
star
44

vsofflinelayout

Guided interface for creating an offline layout for Visual Studio 2017
C#
1
star
45

GetIPlayerUI

Windows front end for get_iplayer
C#
1
star
46

learnvs

Learn Visual Studio: an experimental toolwindow to help you learn Visual Studio basics from within the IDE.
C#
1
star
47

AndroidReminders

Based on Apress Learn Android Studio book
Java
1
star