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
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,11 @@ BYREF/InOut, and output-ownership shapes.
Classic COM generation currently emits JavaScript and TypeScript only. It uses
the separate `@microsoft/dynwinrt/com` public surface; generated wrappers call
`@microsoft/dynwinrt/com/unsafe` internally after codegen validates the ABI.
The `@microsoft/dynwinrt` package root remains WinRT-only.
Generated COM modules use the same lowercase/kebab namespace layout as WinRT
under `com/`, while the COM barrel keeps globally unique short exports.
COM-only generated packages also require the explicit `com/` entrypoint; the
generated package root and `@microsoft/dynwinrt` runtime root remain
WinRT-only.

- [Classic COM JavaScript usage guide](docs/guides/windows/classic-com-usage.md)
- [Supported ABI, coverage, limitations, and ownership model](docs/architecture/classic-com-support.md)
Expand Down
10 changes: 5 additions & 5 deletions bindings/js/__test__/generated-unsafe-companion.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ test.serial('actual generated IWbemServices and IAudioClient companions use hard
t.true(lstatSync(externalJunction).isSymbolicLink())
t.is(readFileSync(sentinel, 'utf8'), 'outside-target-must-survive')

const deepBase = join(output, 'com', 'unsafe', 'Windows', 'Win32', 'System', 'Wmi', 'IWbemServicesUnsafe')
const audioBase = join(output, 'com', 'unsafe', 'Windows', 'Win32', 'Media', 'Audio', 'IAudioClientUnsafe')
const deepBase = join(output, 'com', 'unsafe', 'windows', 'win32', 'system', 'wmi', 'IWbemServicesUnsafe')
const audioBase = join(output, 'com', 'unsafe', 'windows', 'win32', 'media', 'audio', 'IAudioClientUnsafe')
const runner = join(output, 'generated-companion-runner.cjs')
writeFileSync(
runner,
Expand Down Expand Up @@ -121,7 +121,7 @@ test.serial('actual generated IWbemServices and IAudioClient companions use hard
` const esmBarrel = await import(pathToFileURL(${JSON.stringify(join(output, 'com', 'unsafe', 'index.mjs'))}).href)`,
" assert.equal(typeof cjs.IWbemServicesUnsafe, 'function')",
" assert.equal(typeof audio.IAudioClientUnsafe, 'function')",
' assert.equal(cjs.IWbemServicesUnsafe.support.schemaVersion, 10)',
' assert.equal(cjs.IWbemServicesUnsafe.support.schemaVersion, 11)',
" const openNamespaceSupport = cjs.IWbemServicesUnsafe.support.methods.find(method => method.name === 'OpenNamespace')",
" assert.equal(openNamespaceSupport.status, 'raw_metadata_complete')",
" assert.deepEqual(openNamespaceSupport.reasons, [])",
Expand Down Expand Up @@ -655,8 +655,8 @@ test.serial('actual generated IWbemServices and IAudioClient companions use hard
writeFileSync(
consumer,
[
"import { IWbemServicesUnsafe } from './com/unsafe/Windows/Win32/System/Wmi/IWbemServicesUnsafe.js'",
"import { IAudioClientUnsafe } from './com/unsafe/Windows/Win32/Media/Audio/IAudioClientUnsafe.js'",
"import { IWbemServicesUnsafe } from './com/unsafe/windows/win32/system/wmi/IWbemServicesUnsafe.js'",
"import { IAudioClientUnsafe } from './com/unsafe/windows/win32/media/audio/IAudioClientUnsafe.js'",
"import { IWbemServicesUnsafe as FromBarrel } from './com/unsafe/index.js'",
"import { UnsafePointee, UnsafePointerOutput } from './com/unsafe/runtime.js'",
"import type { UnsafeOwnedPointer } from './com/unsafe/runtime.js'",
Expand Down
44 changes: 30 additions & 14 deletions docs/architecture/classic-com-generated-unsafe.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@ metadata does not contain.
```text
generated/
└── com/
├── IFoo.js
├── IFoo.d.ts
├── index.js
├── windows/win32/ui/shell/
│ ├── ITaskbarList3.js
│ └── ITaskbarList3.d.ts
└── unsafe/
├── Windows/Win32/System/Wmi/
├── windows/win32/system/wmi/
│ ├── IWbemServicesUnsafe.js
│ └── IWbemServicesUnsafe.d.ts
├── index.js
Expand All @@ -70,8 +71,12 @@ Rules:
- the npm package root and `@microsoft/dynwinrt/com` remain unchanged.
- a safe-complete interface does not need a duplicate unsafe companion unless a
future explicit diagnostic feature requests one.
- unsafe module paths include every namespace segment. The class inside remains
the ergonomic short `<Interface>Unsafe` name.
- safe and unsafe module paths use the same lowercase/kebab namespace mapping
as canonical WinRT JavaScript output. Class names preserve their metadata
spelling.
- generated imports are relative between canonical modules. The safe root
barrel omits ambiguous short exports while both deep modules remain
available.

## Class and method naming

Expand All @@ -94,8 +99,8 @@ same class; the preferred design keeps them in separate companion classes.
`Contoso.A.IFoo` and `Contoso.B.IFoo` therefore generate:

```text
com/unsafe/Contoso/A/IFooUnsafe.js
com/unsafe/Contoso/B/IFooUnsafe.js
com/unsafe/contoso/a/IFooUnsafe.js
com/unsafe/contoso/b/IFooUnsafe.js
```

If an unsafe class short name is globally unique in `support.json`, the unsafe
Expand Down Expand Up @@ -450,10 +455,10 @@ Generation emits `generated/com/unsafe/support.json`:

```json
{
"schemaVersion": 10,
"schemaVersion": 11,
"interfaces": [
{
"schemaVersion": 10,
"schemaVersion": 11,
"metadata": {
"setSha256": "...",
"files": [
Expand Down Expand Up @@ -557,6 +562,10 @@ dynwinrt-codegen generate `
--output generated
```

Package import names remain unchanged. A relative `--import-name` is interpreted
from `generated/com/` and rebased for each canonical safe module, unsafe
companion, and shared unsafe runtime file.

Possible outcomes:

| Result | Exit behavior |
Expand Down Expand Up @@ -649,12 +658,16 @@ trailing dots/spaces, and Windows device names (`CON`, `PRN`, `AUX`, `NUL`,
`CLOCK$`, `CONIN$`, `CONOUT$`, `COM1`-`COM9`, and `LPT1`-`LPT9`), including
device names with extensions.

Retained schema-9 `modulePath` is never trusted. Codegen rederives it from the
Retained schema-11 `modulePath` is never trusted. Codegen rederives it from the
validated qualified interface identity and exact `<Interface>Unsafe` class
name, requires an exact match, and then checks the case-insensitive path key.
Case-only namespaces or type names therefore fail instead of aliasing on
Windows.

Manifest v2 records canonical safe and unsafe paths. Manifest or support schema
mismatches fail closed; version upgrades require deleting and regenerating the
complete bindings output rather than migrating files in place.

Before overwriting a staged path owned by any manifest root outside the current
update set, codegen requires the retained and planned path identities to match,
requires the staged file to exist, and byte-compares its contents. Shared
Expand All @@ -670,8 +683,11 @@ remain allowed.

## Compatibility invariants

- Existing safe-complete generated output is byte-for-byte unchanged.
- Existing safe output paths and package exports are unchanged.
- Existing generated COM classes, declarations, and root barrel symbols retain
their public names; their deep module paths intentionally move to canonical
namespace directories.
- Version-mismatched output is rejected instead of producing a mixed flat and
canonical layout.
- Unsafe symbols never appear in a safe barrel or safe declaration file.
- Existing WinRT generation is unchanged.
- Existing Classic COM safe generation never changes a class into an unsafe
Expand All @@ -682,7 +698,7 @@ remain allowed.
- Concurrent processes targeting the same output serialize the complete
incremental merge, including successful classes and report-only entries.
- The entire output root is replaced transactionally. COM is never published
before root compatibility barrels and package metadata are ready.
before COM barrels and package metadata are ready.

## Validation

Expand Down Expand Up @@ -745,7 +761,7 @@ Stage 2 is implemented:
arguments;
- parameter requirements come from the same per-target classifier analysis;
- runtime-blocked methods remain omitted;
- support schema 9 records every parameter index/name, strategy type, exact
- support schema 11 records every parameter index/name, strategy type, exact
reason, native direction/nullability, and known target pointee layouts; and
- a raw pointer is never substituted for missing ownership.

Expand Down
23 changes: 13 additions & 10 deletions docs/architecture/classic-com-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ not be described as solving every problem in the map above.
| Explicit COM initialization | Activation no longer silently chooses MTA; callers select STA or MTA with `initializeCom()`. Generated implementation files use the isolated unsafe runtime internally. |
| Dynamic JavaScript COM implementations | Any `IUnknown`-rooted interface whose complete contiguous vtable maps to the validated callback subset receives `static implement()` and `static implementation()`. Static fast-path thunks cover common signatures; cached libffi closures cover arbitrary supported parameter counts, scalar widths, POD layouts, outputs, and native return conventions using the platform COM calling convention. Objects support derived/base IID aliases, multiple interface views, canonical IUnknown identity, shared atomic AddRef/Release, synchronous owner-thread JS dispatch, required Out initialization/validation, allocator-correct transfer, and panic/exception containment. Count/capacity values are read according to their In/InOut ABI direction, fixed outputs without an actual-length slot require exact size, and typed interface outputs are queried to the declared IID. QI references, BSTR/HSTRING values, and CoTaskMem buffers remain RAII-owned until every output is prepared; only then are all native output slots committed, so preparation failure leaves owned outputs null and releases every temporary owner. Wrong-thread HRESULT methods return `RPC_E_WRONG_THREAD`; direct returns are zeroed and void methods do nothing because those native ABIs have no error channel. `IFileDialogEvents` is live-tested with `Advise`/`Unadvise`; `IDropTarget` exercises libffi, POD/InOut, generated multi-interface composition, and QueryInterface. |
| Fail-closed generation | Unknown/unsafe layouts, untagged/by-value/output unions, bitfields, flexible arrays, nested owned fields, unsupported VARTYPE/BYREF/SAFEARRAY/PROPVARIANT combinations, unsupported arrays, pointer outputs, ownership, and in/out shapes stop generation with a targeted error. |
| Consumable output | Classic COM files live under `com/`, with `./com` and `./com/*` package exports. Mixed and incremental generation preserve the WinRT-only root barrel; COM-only output retains its legacy root entrypoint. |
| Consumable output | Classic COM files live under `com/`, with `./com` and `./com/*` package exports. The generated package root is always WinRT-only; COM-only output deliberately has no root entrypoint. |
| Explicit vtable registration | Every generated method is registered with `.addMethodAt(vtableIndex, name, signature)`, keyed by its actual metadata-derived vtable slot. Methods are never deduplicated by name, so same-name overloads at different slots both register correctly. |
| Same-name overload projection | Overloads (e.g. `IDCompositionEffectGroup::SetOpacity`) are grouped once during projection (not by renderer heuristics). A single public JS method dispatches to a private per-slot implementation using only a validated, mutually-distinguishable arity/shape key (`typeof`-based: boolean/number/bigint/string/object); ambiguous groups fail generation closed with a diagnostic naming the interface, method, and reason. The `.d.ts` emits one TypeScript overload signature per branch, contiguously. |
| Lifecycle ergonomics | Generated interface wrappers declare a protected constructor (`protected constructor(obj: unknown);`) so only generated coclasses can subclass them. Coclasses expose a public zero-argument constructor, and every wrapper provides an idempotent `release()` that delegates to the managed native value. Factory-activated interop wrappers retain `static create()` with JSDoc reminding callers to initialize COM first. |
Expand Down Expand Up @@ -508,14 +508,15 @@ bindings/
├── index.js
├── index.mjs
├── index.d.ts
├── Uri.js
├── windows/foundation/Uri.js
├── com/
│ ├── package.json
│ ├── index.js
│ ├── index.mjs
│ ├── index.d.ts
│ ├── TaskbarList.js
│ └── ITaskbarList4.js
│ └── windows/win32/ui/shell/
│ ├── TaskbarList.js
│ └── ITaskbarList4.js
└── package.json
```

Expand Down Expand Up @@ -544,14 +545,16 @@ taskbar.release();

Separate WinRT and COM invocations may target the same output directory in
either order. The generated package manifest is rebuilt from both domains
without adding COM exports to the WinRT root. Legacy COM-only output is
relocated automatically when it is reused with the new generator.
without adding COM exports to the WinRT root. Generated layout/schema version
changes require deleting and regenerating the complete bindings directory;
in-place cross-version migration is intentionally unsupported.

winappCli project aliases use `#winapp/bindings/com` for the COM barrel and
`#winapp/bindings/com/InterfaceName` for deep imports. Existing source that
used `#winapp/bindings/InterfaceName` for COM should switch to the `com/`
path. Standalone COM-only packages continue to expose their legacy
package-name deep imports.
canonical deep imports such as
`#winapp/bindings/com/windows/win32/ui/shell/ITaskbarList3`. Existing source
that used a flat COM deep import should switch to the canonical namespace path.
Standalone COM-only packages also require the explicit `com/` prefix; package
root imports do not expose COM symbols.

### Explicit unsafe/raw opt-in

Expand Down
12 changes: 6 additions & 6 deletions docs/guides/windows/classic-com-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ remain intact.
The ordinary command has no unsafe opt-in flag. If complete safe projection
fails but one or more methods are `raw_metadata_complete`, codegen writes an
isolated namespace-qualified companion such as
`generated/com/unsafe/Windows/Win32/System/Wmi/IWbemServicesUnsafe.js` and
records every method in `support.json`. Safe-complete interfaces keep their
existing output unchanged.
`generated/com/unsafe/windows/win32/system/wmi/IWbemServicesUnsafe.js` and
records every method in `support.json`. Safe-complete interfaces use matching
canonical namespace directories under `generated/com/`.

```powershell
npx dynwinrt-codegen generate `
Expand Down Expand Up @@ -194,8 +194,8 @@ The short barrel export is available only while `IWbemServicesUnsafe` is
globally unique. If two namespaces contain `IFoo`, import their deep modules:

```js
import { IFooUnsafe as FooA } from "./generated/com/unsafe/Contoso/A/IFooUnsafe.js";
import { IFooUnsafe as FooB } from "./generated/com/unsafe/Contoso/B/IFooUnsafe.js";
import { IFooUnsafe as FooA } from "./generated/com/unsafe/contoso/a/IFooUnsafe.js";
import { IFooUnsafe as FooB } from "./generated/com/unsafe/contoso/b/IFooUnsafe.js";
```

The ambiguous `IFooUnsafe` short export is omitted until one root is removed.
Expand Down Expand Up @@ -485,7 +485,7 @@ creates a safe `create()` method:

```js
import { initializeCom } from "@microsoft/dynwinrt/com";
import { IDataTransferManagerInterop } from "./generated/com/IDataTransferManagerInterop.js";
import { IDataTransferManagerInterop } from "./generated/com/windows/win32/ui/shell/IDataTransferManagerInterop.js";

initializeCom(1);

Expand Down
9 changes: 5 additions & 4 deletions docs/status/CLASSIC_COM_API_SUPPORT_PLAN.md
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ non-addressable identities block every method before companion selection.
`MFASYNCRESULT` therefore produces no callable class.

When an interface has no executable method, generation transactionally commits
a schema-9 report containing every blocked/manual method and exact reasons,
a schema-11 report containing every blocked/manual method and exact reasons,
emits no class `.js`/`.d.ts`, and then exits nonzero. The metadata record is a
sorted, deduplicated set of every loaded emission/reference/sibling winmd, with
per-file hashes, a set hash, and an optional exact defining file; it contains no
Expand All @@ -277,8 +277,9 @@ pre-publication rollback. No-follow residue cleanup removes only the links,
never an external target. Case aliases, managed/staged/manifest ownership
conflicts, transaction-residue names, and unsupported reparse tags fail closed.

Unsafe modules include their stable namespace path, for example
`com/unsafe/Windows/Win32/System/Wmi/IWbemServicesUnsafe.js`. The short class
Safe and unsafe modules use the canonical lowercase/kebab namespace layout, for
example `com/windows/win32/ui/shell/ITaskbarList3.js` and
`com/unsafe/windows/win32/system/wmi/IWbemServicesUnsafe.js`. The short class
name remains `IWbemServicesUnsafe`. A short barrel export is emitted only when
globally unique; ambiguous names are available only through deep modules, and
incremental order does not affect the resulting barrel.
Expand All @@ -304,7 +305,7 @@ generated `runtime.js`/`.d.ts` provides closed pointee, pointer-output, handle,
interface-replacement, counted-buffer, owned-pointer, and raw-fallback
strategies. Generated methods validate strategy types before dispatch, clean
dirty HRESULT failure outputs according to the selected strategy, and report
exact per-parameter requirements in support schema 9.
exact per-parameter requirements in support schema 11.

Strategy capabilities are unforgeable frozen objects backed by private
WeakMaps. Private generated helpers perform prepare, writable-span overlap
Expand Down
2 changes: 1 addition & 1 deletion samples/js/electron-share-ui/src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { initializeCom } from '@microsoft/dynwinrt/com'
import { roInitialize } from '@microsoft/dynwinrt'
import { DataTransferManager } from '../../generated/windows/application-model/data-transfer/DataTransferManager.js'
import { projectAs, releaseProjected } from '../../generated/lifetime.js'
import { IDataTransferManagerInterop } from '../../generated/com/IDataTransferManagerInterop.js'
import { IDataTransferManagerInterop } from '../../generated/com/windows/win32/ui/shell/IDataTransferManagerInterop.js'

interface ShareContent {
title: string
Expand Down
2 changes: 1 addition & 1 deletion samples/js/electron-smtc/media-controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const {
} = require("./generated/index.js");
const {
ISystemMediaTransportControlsInterop,
} = require("./generated/com/ISystemMediaTransportControlsInterop.js");
} = require("./generated/com/windows/win32/system/win-rt/ISystemMediaTransportControlsInterop.js");
const { releaseProjected } = require("./generated/lifetime.js");

const TICKS_PER_SECOND = 10_000_000n;
Expand Down
2 changes: 1 addition & 1 deletion samples/js/windows-hello/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const {
} = require('./generated/index.js')
const {
IUserConsentVerifierInterop,
} = require('./generated/com/IUserConsentVerifierInterop.js')
} = require('./generated/com/windows/win32/system/win-rt/IUserConsentVerifierInterop.js')

const resultType = DynWinRtType.enumType(
'Windows.Security.Credentials.UI.UserConsentVerificationResult',
Expand Down
6 changes: 3 additions & 3 deletions tests/e2e/runners/com/automation-dispatch.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import { DynComUnsafe } from "../../../../bindings/js/dist/com-unsafe.js";
import {
IDispatch,
IID_IDispatch,
} from "../../e2e_generated/com/automation/com/IDispatch.js";
import { IEnumVARIANT } from "../../e2e_generated/com/automation/com/IEnumVARIANT.js";
import { IStream } from "../../e2e_generated/com/stream/com/IStream.js";
} from "../../e2e_generated/com/automation/com/windows/win32/system/com/IDispatch.js";
import { IEnumVARIANT } from "../../e2e_generated/com/automation/com/windows/win32/system/ole/IEnumVARIANT.js";
import { IStream } from "../../e2e_generated/com/stream/com/windows/win32/system/com/IStream.js";

const CLSID_SHELL_APPLICATION = "13709620-c279-11ce-a49e-444553540000";
const DISPATCH_PROPERTYGET = 2;
Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/runners/com/drop-target.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import { DynCom } from "../../../../bindings/js/dist/com-unsafe.js";
import {
createPOINTL,
IDropTarget,
} from "../../e2e_generated/com/shell/com/IDropTarget.js";
import { IFileDialogEvents } from "../../e2e_generated/com/shell/com/IFileDialogEvents.js";
} from "../../e2e_generated/com/shell/com/windows/win32/system/ole/IDropTarget.js";
import { IFileDialogEvents } from "../../e2e_generated/com/shell/com/windows/win32/ui/shell/IFileDialogEvents.js";

DynCom.initialize(0);

Expand Down
Loading
Loading