Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,14 @@ contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additio

- **Rust** (stable, 2024 edition)
- **Windows 10/11** with Windows SDK installed
- **Node.js 18+** for the JavaScript binding and generated JavaScript tests
- **CPython 3.11–3.14** plus `maturin` for the Python binding
- **libffi** (bundled via the `libffi` crate)

Some suites also require Windows App SDK metadata/runtime assets or
`Microsoft.Windows.SDK.Win32Metadata`; the test scripts skip optional suites
unless those inputs are explicitly required.

### Building

```bash
Expand All @@ -28,6 +34,12 @@ cargo build -p dynwinrt

# Build the code generator
cargo build -p dynwinrt-codegen

# Build the JavaScript binding
(cd bindings/js && npm install && npm run build)

# Build/install the Python binding
(cd bindings/py && python -m maturin develop)
```

### Running Tests
Expand All @@ -38,6 +50,15 @@ cargo test -p dynwinrt

# Code generator tests
cargo test -p dynwinrt-codegen

# JavaScript tests
(cd bindings/js && npm test)

# Python tests
(cd bindings/py && python -m pytest)

# End-to-end tests (auto-detects available metadata)
pwsh -File ./tests/e2e/e2e_test.ps1
```

### Coverage
Expand Down Expand Up @@ -76,7 +97,7 @@ Please use the provided issue templates when available.

1. Fork the repo and create your branch from `main`
2. If you've added code, add tests that cover the new functionality
3. Ensure all tests pass (`cargo test`)
3. Ensure the relevant Rust and language-binding tests pass
4. Run `cargo clippy` and address any warnings
5. Submit your pull request

Expand Down
173 changes: 120 additions & 53 deletions README.md

Large diffs are not rendered by default.

18 changes: 12 additions & 6 deletions bindings/js/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# @microsoft/dynwinrt

**Call any Windows Runtime (WinRT) API from JavaScript — without writing a native addon.**
**Call Windows Runtime (WinRT) APIs from JavaScript — without writing a native addon.**

`dynwinrt` is a runtime library that lets your Node.js or Electron code call modern Windows APIs (WinAppSDK, Windows AI, notifications, file pickers, sensors, storage, networking, …) **directly from JavaScript / TypeScript**, with full IntelliSense, no MSBuild step, no C++ or C# project, and no per-Windows-version recompile.

Expand All @@ -12,7 +12,12 @@ If you've ever tried to call a Windows API from an Electron or Node app, you've
- **Writing a C# addon via `node-api-dotnet`.** Needs the .NET SDK, a separate `csproj` build step, and a manually-maintained C# wrapper for every API surface you want to expose.
- **Waiting for a typed projection.** Some Windows APIs ship `.winmd` metadata months before any JavaScript-friendly projection appears in a published package.

`dynwinrt` removes all of that. It reads the `.winmd` metadata that ships with the Windows SDK (and WinAppSDK NuGet packages) at **runtime**, resolves the COM vtables, and invokes WinRT methods dynamically. There is no native build step in your Electron project. There is no version pinning — the same generated bindings work across Windows SDK / WinAppSDK revisions as long as the metadata is forward-compatible. You just install `@microsoft/dynwinrt` from npm and call the API.
`dynwinrt-codegen` reads the `.winmd` metadata that ships with the Windows SDK
and WinAppSDK ahead of time. The generated JavaScript registers the required
interface signatures, and `dynwinrt` resolves and invokes the COM vtables
dynamically at runtime. There is no native build step in the consuming Electron
or Node project. The same generated bindings can work across compatible
metadata revisions without rebuilding a native addon.

The runtime primarily targets **data-style WinRT APIs** (AI, storage, notifications, networking, globalization, …). It also supports WinUI `Application + Window` hosting through the generated `Application.create()` helper when the caller supplies an STA UI thread, an initialized Windows App SDK runtime, and application lifecycle. Unpackaged callers can initialize the runtime with `initWinappsdk()`; the helper resolves the framework resources from that package graph. It also enables Per-Monitor V2 DPI awareness on the UI thread.

Expand Down Expand Up @@ -64,8 +69,8 @@ contains duplicate short names, each canonical module keeps its native symbol
name while the root barrel uses a namespace-qualified name, such as
`AIFoundationEmbeddingVector` or `SemanticSearchEmbeddingVector`.

Classic COM uses a separate subpath from the same package, keeping the WinRT
root API unchanged:
Classic COM is a preview under active development. It uses a separate subpath
from the same package, keeping the WinRT root API unchanged:

```js
const { initializeCom } = require('@microsoft/dynwinrt/com');
Expand All @@ -83,7 +88,8 @@ type-specific cleanup function.

See the repository's
[Classic COM JavaScript usage guide](../../docs/guides/windows/classic-com-usage.md) for
codegen, GUID/IID/CLSID, lifetime, Automation, and `/com/unsafe` examples.
codegen, current coverage and limitations, GUID/IID/CLSID, lifetime, Automation,
and `/com/unsafe` examples.

Unambiguous public WinRT activation metadata is projected as JavaScript constructors.
Parameterized and composable activations support idiomatic forms such as
Expand Down Expand Up @@ -140,7 +146,7 @@ properties, and codegen emits the paired `IVector<T>` binding automatically.
## Platform support

- **Windows 10 / 11** — x64 and arm64 native binaries shipped via `napi-rs` prebuilds
- **Node.js** ≥ 16 (Electron, plain Node, vscode extensions, …)
- **Node.js** ≥ 18 (Electron, plain Node, VS Code extensions, …)

## Links

Expand Down
39 changes: 28 additions & 11 deletions design.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Dynamic Projection for JavaScript and Python

> **Status: historical design record.** This document preserves the original
> motivation and alternatives considered for dynwinrt. The shipped
> implementation uses design-time generation: `dynwinrt-codegen` reads WinMD
> and emits JavaScript/TypeScript or Python wrappers, while the native runtime
> executes their registered ABI signatures. It does not lazily parse WinMD when
> an application accesses a namespace. See the root [README](README.md) and
> current [roadmap](docs/status/TODO.md) for supported behavior.

## Objective

The primary objective of this project is to expose WinRT Windows APIs to dynamic languages, specifically JavaScript and Python, while ensuring a seamless developer experience. This approach eliminates the need for native compilation (such as C++ compilers) and removes strict version coupling between the projection and the Windows App SDK (WASDK) components.
Expand All @@ -8,7 +16,10 @@ The primary objective of this project is to expose WinRT Windows APIs to dynamic

### Versioning Complexity

Current static projections, such as existing PyWinRT, necessitate the generation and compilation of native code for specific versions of WinRT components. This requirement results in a complex compatibility matrix and mandates the release of new projection packages for every WASDK release, and more importantly, does not expose full WinRT APIs to developers due to AOT compilation constraints.
Static projections such as PyWinRT generate and compile native code for specific
WinRT components. This creates a compatibility matrix and requires projection
packages to track Python, architecture, Windows SDK, and Windows App SDK
releases.

### Developer Experience (DX)

Expand Down Expand Up @@ -56,9 +67,9 @@ This infrastructure can be mostly shared across dynamic languages.

This component bridges the gap between raw WinMD metadata and the runtime projection, operating in two distinct modes:

#### Mode A: Fully Lazy Assessment (Runtime)
#### Mode A: Fully Lazy Assessment (Runtime, not shipped)

In this mode, the runtime parses `.winmd` files on the fly as APIs are accessed.
This alternative would parse `.winmd` files on the fly as APIs are accessed.
* **Advantages**: Proven stability in previous JavaScript projections and simpler distribution (no generation step required).
* **Disadvantages**: Incurs runtime parsing overhead (potentially negligible compared to marshalling) and lacks IDE IntelliSense support.

Expand All @@ -76,15 +87,19 @@ The usage workflow involves two stages:
The runtime is distributed as a generic library for the target language (e.g., `npm install @microsoft/dynwinrt` or `pip install dynwinrt`).

### Step 2: Projection Usage
Developers have two options for using the projection:
1. **Direct Usage**: The runtime directly supports runtime interface specifications. Developers can use libraries directly by lazily loading namespaces with distributed WinMDs. The runtime parses the WinMDs and generates necessary interface shapes on the fly.
2. **Generated Bindings**: Alternatively, developers can execute a tool (e.g., `npx dynwinrt-codegen generate ...`) to generate bindings and types specifically for the WinMDs they intend to use.
The shipped workflow uses generated bindings. Developers run
`dynwinrt-codegen generate ...` to create wrappers and types for the WinMDs
they intend to use, then load those wrappers with the generic runtime package.
The lower-level runtime interface-registration API remains available, but no
lazy namespace/WinMD loader is shipped.

## Performance Considerations

### Overhead Analysis

The primary performance costs are attributed to WinMD parsing (in lazy mode) and the overhead of dynamic WinRT method invocation (dynamic dispatch). This invocation overhead is expected to be comparable to existing marshalling costs associated with crossing the JavaScript/Python boundary.
The shipped design-time mode removes WinMD parsing from application startup.
Runtime costs are native-language boundary conversion, ABI marshaling, and
dynamic vtable dispatch.

### Optimization Strategies

Expand Down Expand Up @@ -158,11 +173,13 @@ HRESULT Method_Out_Pointer(void* funPtr, ComPtr self, void* outValue) {
}
```

### Known Challenges
### Original challenges and current tracking

* **Signature Casting**: Proper handling of GUID casting is required, particularly for type-safety and generics.
* **Representation Mapping**: Special handling is needed for JavaScript/Python representations; for example, `IVector` may need to map to a function rather than a simple interface instance.
* **Async Operations**: While mentioned, the handling of asynchronous operations requires robust implementation details.
Parameterized IIDs, language-native collections, async operations, delegates,
structs, nullable references, and generated type information are implemented.
Remaining correctness, coverage, lifecycle, and developer-experience work is
tracked in [`docs/status/TODO.md`](docs/status/TODO.md) and
[`docs/status/PYTHON_CHECKLIST.md`](docs/status/PYTHON_CHECKLIST.md).

## References

Expand Down
6 changes: 6 additions & 0 deletions docs/architecture/classic-com-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
`dynwinrt` supports a deliberately limited subset of Classic COM. It is not a
general Automation or native Win32 projection.

> **Status: preview, under active development.** The current CI baseline against
> `Microsoft.Windows.SDK.Win32Metadata` 71.0.14-preview is 5,567 complete safe
> interface projections out of 7,929 eligible interfaces (70.21%). Earlier
> inventory and demand-snapshot sections retain the metadata versions and dates
> stated in those sections.

For installation and application-facing examples, including GUID/IID/CLSID
and `/com/unsafe`, see
[Classic COM JavaScript usage](../guides/windows/classic-com-usage.md).
Expand Down
4 changes: 4 additions & 0 deletions docs/benchmarks/BENCHMARK.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# End-to-End Performance: Electron IPC

> **Recorded benchmark snapshot (August 2026).** These numbers describe the
> hardware and software environment below; they are not continuously updated.
> Re-run the command at the end of this document for current results.

Benchmark for the full Electron UI call path: **Renderer → IPC → Main Process → native addon → WinRT → IPC → Renderer**.

This demonstrates that **dynwinrt has no meaningful performance impact** in real Electron applications — IPC serialization dominates all native-layer differences.
Expand Down
9 changes: 7 additions & 2 deletions docs/benchmarks/BENCHMARK_ANALYSIS.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
# Native Layer Performance Analysis

> **Recorded benchmark snapshot (August 2026).** These measurements document a
> specific implementation and machine, not a permanent performance guarantee.
> Re-run the commands at the end of this document before making current
> performance decisions.

Benchmark for direct napi calls (no Electron IPC). Measures the actual overhead of dynwinrt's dynamic dispatch compared to static C++/WinRT projections.

Environment: AMD Ryzen 9 7940HX, Windows 11, Node.js v22. All Rust builds: release + LTO + codegen-units=1.

---

## Current Performance (napi-rs standard path)
## Recorded Performance (napi-rs standard path)

JS → **napi-rs** → **dynwinrt** (Rust + libffi) → COM vtable.

Expand Down Expand Up @@ -130,7 +135,7 @@ Specialized methods that combine invoke + result extraction into a single napi c

## Theoretical Performance Limits

### Current: napi-rs macro path (~1-3 µs overhead)
### Recorded production path: napi-rs macros (~1-3 µs overhead)

Our production path uses napi-rs macros for ergonomic Rust ↔ JS bindings. The napi-rs layer adds 75-170 ns per call for type checking and string roundtrips, plus each `DynWinRtValue` argument or result extraction is an extra napi boundary crossing (~500-1000 ns each).

Expand Down
4 changes: 3 additions & 1 deletion docs/guides/node/dev-mode.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ This exposes the active Node installation at `.local-node` without copying its f
npx winapp manifest add-alias --name mynode.exe --manifest .\Package.appxmanifest
```

This inserts an [`<uap3:Extension Category="windows.appExecutionAlias">`](https://learn.microsoft.com/en-us/uwp/schemas/appxpackage/uapmanifestschema/element-uap3-appexecutionalias) into the manifest, pointing at `.local-node\node.exe`.
This inserts a
[`<uap5:AppExecutionAlias>`](https://learn.microsoft.com/en-us/uwp/schemas/appxpackage/uapmanifestschema/element-uap5-appexecutionalias)
extension into the manifest, pointing at `.local-node\node.exe`.

### 3. Register the loose-layout package

Expand Down
22 changes: 14 additions & 8 deletions docs/guides/python/python-ui-ecosystem.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
# WinRT in the Python UI Ecosystem: Adoption and the Value of dynwinrt

> Research snapshot: July 20, 2026
>
> **Current project status:** since this research was collected, the
> [`dynwinrt`](https://pypi.org/project/dynwinrt/) runtime and standalone
> [`dynwinrt-codegen`](https://pypi.org/project/dynwinrt-codegen/) command have
> shipped as PyPI previews. Numerical ecosystem data below remains a dated
> research snapshot.

## What this research asks

Is there real user value in adding Python support to dynwinrt?
Is there real user value in dynwinrt's Python support?

**Yes, but the value is not in creating another Python UI framework.**

Python developers already build user interfaces with Qt, Tkinter, wxPython,
Kivy, and pywebview. Those applications still need Windows-specific features
such as notifications, media controls, OCR, Wi-Fi, Bluetooth, sensors, and
system colors. Today, they primarily access those APIs through the static
pywinrt projection.
system colors. At the time of this snapshot, they primarily accessed those APIs
through the static pywinrt projection.

Public data shows that:

Expand All @@ -26,8 +32,8 @@ Public data shows that:
BLE, notifications, and OCR are more common.

The audience for dynwinrt Python support is therefore developers who already
have a UI framework but still need Windows APIs. dynwinrt would provide the
Windows API access layer, not replace the UI framework.
have a UI framework but still need Windows APIs. dynwinrt provides the Windows
API access layer; it does not replace the UI framework.

## Terminology

Expand All @@ -36,7 +42,7 @@ Windows API access layer, not replace the UI framework.
| UI framework | Provides windows, controls, and UI events. Examples include PyQt, PySide, Tkinter, and wxPython. |
| WinRT | A set of Windows system APIs for capabilities such as notifications, media, OCR, Bluetooth, and sensors. |
| Python projection | Converts WinRT COM/ABI interfaces into ordinary Python classes, methods, and events. |
| pywinrt | The current active static Python projection. Each WinRT namespace is generated and compiled into a wheel ahead of time. |
| pywinrt | The active static Python projection at the time of this snapshot. Each WinRT namespace is generated and compiled into a wheel ahead of time. |
| dynwinrt | Generates lightweight Python wrappers and invokes the WinRT ABI through a shared native runtime. |

"Python UI framework" describes the API used by Python developers, not
Expand Down Expand Up @@ -231,7 +237,7 @@ that calling WinRT from Python is not merely an experimental niche.
|---|---|---|
| Microsoft `winrt` | Discontinued after 2021 | Covers only CPython 3.7-3.9 and x86/x64 |
| Community `winsdk` | Archived | Monolithic package supporting CPython 3.8-3.12 and ARM64 |
| Current `pywinrt` | Active solution | One `winrt-*` wheel per namespace; supports CPython 3.9-3.14 and x86/x64/ARM64 |
| `pywinrt` (July 2026) | Active solution | One `winrt-*` wheel per namespace; supports CPython 3.9-3.14 and x86/x64/ARM64 |

The continued presence of all three generations shows both sustained demand and
the maintenance burden of a static projection. It must track:
Expand Down Expand Up @@ -270,7 +276,7 @@ does not require another purpose-built native extension.
| Custom WinMD | Build and maintain a dedicated native projection | Use the same code generator and runtime |
| Python and JavaScript | Maintain separate projection and runtime implementations | Share the Rust ABI core |
| UI framework | Framework-independent | Also framework-independent |
| Current maturity | Production users and broad API coverage | Python support is still evolving; coverage depends on the runtime |
| Maturity | Production users and broad API coverage | Published preview; coverage depends on the shared runtime's supported ABI types |

For an existing Python UI application, the practical value is:

Expand Down
7 changes: 7 additions & 0 deletions docs/guides/windows/classic-com-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
This guide explains how to use `dynwinrt` to call Classic COM from Node.js/Electron and how to correctly handle
GUIDs, IIDs, CLSIDs, and REFIIDs.

> **Status: preview, under active development.** Generated bindings are
> available for interfaces whose complete ABI, layout, ownership, and cleanup
> contracts are validated. Unsupported interfaces fail closed instead of
> emitting a partial wrapper. See
> [Classic COM support](../../architecture/classic-com-support.md) for the
> current coverage baseline and known gaps.

> Prefer the safe bindings generated by `dynwinrt-codegen`. Use `@microsoft/dynwinrt/com/unsafe` only when the
> metadata cannot fully describe the ABI and you have verified every calling convention against the native headers
> and Microsoft documentation.
Expand Down
6 changes: 3 additions & 3 deletions docs/guides/windows/msix-packaging.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

This guide shows how to package a Node.js application that uses
`@microsoft/dynwinrt` into an MSIX with
[WinApp CLI](https://github.com/microsoft/WinAppCli) 0.5.0.
[WinApp CLI](https://github.com/microsoft/WinAppCli) 0.6.2.

The process first creates an application-specific Node
[Single Executable Application (SEA)](https://nodejs.org/api/single-executable-applications.html).
Expand All @@ -20,7 +20,7 @@ Create a Node.js project:
mkdir my-dynwinrt-app
cd my-dynwinrt-app
npm init -y
npm install --save-dev @microsoft/winappcli@0.5.0
npm install --save-dev @microsoft/winappcli@0.6.2
npx winapp init . --use-defaults --add-js-bindings
```

Expand Down Expand Up @@ -322,7 +322,7 @@ For ARM64, repeat the SEA build with the same Node version's
[`win-arm64/node.exe`](https://nodejs.org/dist/v24.19.0/win-arm64/node.exe)
and the ARM64 dynwinrt runtime.

WinApp CLI 0.5.0 can create a multi-architecture bundle directly:
WinApp CLI 0.6.2 can create a multi-architecture bundle directly:

```powershell
npx winapp pack `
Expand Down
Loading
Loading