win32 Dart Package

website·Indexed 32 days ago

https://win32.pub/

Dart FFI bindings to a subset of the Win32 API, allowing developers to call Windows APIs directly from Dart. The package includes support for C structs, COM methods with idiomatic Dart signatures, and native memory allocation. Recent versions include v6.0.0 and v6.3.0.

Tokens
18.7K
Snippets
99
Records
189
Agent score
64%

What's inside win32

  1. Overview of native memory leak tracking with ffi_leak_tracker

    The package:ffi_leak_tracker allows developers to identify native memory leaks in Dart FFI code by tracking allocations made through its specific allocators. It records the address, size, type, call stack, and timestamp of each allocation.

    Key constraints:

    • Tracking is opt-in and disabled by default.
    • Only allocations made via ffi_leak_tracker allocators are tracked; direct calls to calloc() or malloc() are not visible to the tracker.
    • Adaptive allocators have zero overhead in release builds as they compile away to standard calloc()/malloc().
  2. Use ffi_leak_tracker for Dart FFI memory management

    Use the ffi_leak_tracker package to implement allocation tracking and leak detection for Dart FFI code.
  3. Run Flutter apps without C/C++ using win32_runner

    The win32_runner package allows you to compile and run a Flutter app using only Dart, removing the need for C/C++ code in the runner.
  4. Win32 package v5.0.0 architecture and API requirements

    Version 5.0.0 introduces the following breaking changes and requirements:

    • Architecture: 32-bit architectures are no longer supported; the package now assumes 64-bit.
    • WinRT APIs: Experimental WinRT APIs have been removed. Users should migrate to the new windows_* packages.
  5. Access the Windows Clipboard with win32_clipboard

    The win32_clipboard package provides a friendly Dart API for interacting with the Windows Clipboard.
  6. Understand native memory requirements for Dart FFI

    Dart is a garbage-collected language, but this model does not extend across the FFI boundary. Only primitive values (like integers) can be passed directly. All other data—such as strings, structs, and buffers—must reside in native memory. Developers are responsible for the lifetime of native memory; failing to release it will exhaust the native heap and destabilize the application.
  7. Use named pipe APIs for pty projects

    Version 2.0.2 introduces named pipe APIs specifically designed to support projects requiring pseudo-terminal (pty) functionality, such as TerminalStudio.
  8. Use package:win32 for native Windows functionality in Dart and Flutter

    package:win32 provides Dart FFI bindings to a subset of Win32 and COM (Component Object Model) APIs. It is intended for scenarios where native Windows functionality is required that is not available via dart:io, Flutter plugins, or platform channels. Common use cases include:

    • Flutter apps on Windows: Accessing system settings, hardware devices, registry data, and native dialogs.
    • Cross-platform packages: Implementing Windows-specific backends for shared platform interfaces.
    • CLI tools and background services: Accessing native file, process, registry, and security APIs in headless contexts.
  9. Understand the Win32 Dart FFI architecture

    The package:win32 is built upon two primary Dart FFI components:

    1. dart:ffi: The core library for declaring native functions, handling pointers, and mapping C types to Dart types.
    2. package:ffi: Provides higher-level utilities for common tasks such as memory allocation and string conversion.
  10. Manage the Windows Registry with win32_registry

    The win32_registry package provides a friendly Dart API for accessing and managing the Windows Registry.
  11. Migrate from win32 v5 to v6: General API Changes

    Version 6.x.x of the win32 package introduces several fundamental changes to improve safety and idiomatic Dart usage:

    • Error Handling: APIs returning HRESULT now throw WindowsException on failure instead of requiring manual FAILED(hr) checks.
    • Return Values: APIs that previously used pointer-based out parameters now return logical output values directly.
    • Last-Error APIs: APIs calling SetLastError() now return a Win32Result<T>, which captures both the return value and the error code.
    • Boolean Mapping: Win32 BOOL (return values, parameters, and struct fields) is now mapped to Dart bool instead of int.
    • Strongly Typed Handles: Opaque handles (e.g., HKEY, HWND, HICON) are now extension types rather than raw int or Pointer.
    • Enums: Win32 enums are now extension types for better type safety while remaining interoperable with int.
    • COM Lifetime: Finalizer is no longer used for automatic COM cleanup. You must call IUnknown.release() explicitly or use Arena for management.
  12. Use filepicker_windows for Windows file selection

    The filepicker_windows package provides file and directory selection capabilities on Windows using common native dialog controls.