Skip to main content

Quick Start

🧩 How Win32 APIs Are Called from Dart

Windows API was originally designed for C developers, so its conventions reflect C's characteristics and capabilities. Fortunately, Dart has first-class support for calling C code through FFI (Foreign Function Interface), which is what package:win32 builds on.

Dart's FFI support is split across two packages:

  • dart:ffi — the core library for declaring and calling native functions, working with pointers, and mapping C types to Dart types.
  • package:ffi — higher-level helpers for common patterns like string conversion and memory allocation.

package:win32 uses both internally, and you will often need them directly in your own code as well.

📦 Installation

Add the required packages to your project:

flutter pub add ffi win32

Then import them wherever you need to make Win32 calls:

import 'dart:ffi';

import 'package:ffi/ffi.dart';
import 'package:win32/win32.dart';

🚀 Calling Your First Win32 API

The Beep function is a good starting point — it takes a frequency in Hz and a duration in milliseconds, and requires no memory management or error handling:

beep.dart
import 'package:win32/win32.dart';

void main() {
Beep(440 /* Hz */, 500 /* ms */);
}

Run this and you should hear an A4 tone play for half a second.

📚 Next Steps

📘 Read the Functions guide to understand how Win32 functions are projected into Dart and how to call them effectively.

🔍 Browse real-life examples that show package:win32 in use across a range of common Windows tasks.

📦 Explore packages built on top of package:win32 for higher-level abstractions that may cover your use case out of the box.