Skip to content

Automatically marshal COM outputs as WinRT - #1771

Merged
Jevan Saks (jevansaks) merged 12 commits into
mainfrom
user/jevansa/com-out-ptr-marshalling-policy
Sep 1, 2026
Merged

Jevan Saks (jevansaks) merged 12 commits into
mainfrom
user/jevansa/com-out-ptr-marshalling-policy

Conversation

@jevansaks

@jevansaks Jevan Saks (jevansaks) commented Jul 30, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Automatically projects recognized COM IID/void** outputs through C#/WinRT when the returned identity implements IInspectable, with COM fallback on E_NOINTERFACE.
  • Enables the behavior by default and adds the comInterop.autoWinRTMarshalling opt-out.
  • Supports flat P/Invoke, generated COM managed call paths, built-in COM, null output, and Native AOT.
  • Preserves existing CsWinRT/source-generated COM RCW identity through ComWrappers.TryGetComInstance and classic COM RCW identity through Marshal.GetIUnknownForObject.
  • Uses generated COM marshalling for [GeneratedComClass] CCWs and C#/WinRT marshalling for ordinary managed CCWs.
  • Documents the selected architecture under docs/design.

Validation

  • Full warning-as-error build and package creation.
  • Full non-hardware and hardware-dependent test suites.
  • Focused .NET 9 and .NET 10 identity, interface, and round-trip tests for CsWinRT RCWs, source-generated COM RCWs, classic COM RCWs, WinRT CCWs, and generated COM CCWs.
  • Fresh package-consumption Native AOT publish and execution of the adaptive marshaller.

Design: #1770

Generated with Copilot CLI, model: GPT-5.6 Sol.

Co-authored-by: Copilot <[email protected]>

Copilot-Session: b24622c7-c9d6-44f0-9a20-85aac5ff11d6
Co-authored-by: Copilot <[email protected]>

Copilot-Session: b24622c7-c9d6-44f0-9a20-85aac5ff11d6
@jevansaks

Copy link
Copy Markdown
Member Author

The first hardware run exposed a test-only environment dependency: SIGDN_NORMALDISPLAY returned win on Windows Server (extensions hidden) instead of win.ini. Commit d26630d now asserts the stable SIGDN_FILESYSPATH; the focused test passes in Release on .NET 9 and .NET 10.

Co-authored-by: Copilot <[email protected]>

Copilot-Session: b24622c7-c9d6-44f0-9a20-85aac5ff11d6
@jevansaks Jevan Saks (jevansaks) changed the title Add COM output pointer marshalling policies Automatically marshal COM outputs as WinRT Jul 31, 2026
Jevan Saks (jevansaks) and others added 6 commits July 31, 2026 00:23
Co-authored-by: Copilot <[email protected]>

Copilot-Session: b24622c7-c9d6-44f0-9a20-85aac5ff11d6
Co-authored-by: Copilot <[email protected]>

Copilot-Session: b24622c7-c9d6-44f0-9a20-85aac5ff11d6
Co-authored-by: Copilot <[email protected]>

Copilot-Session: b24622c7-c9d6-44f0-9a20-85aac5ff11d6
Co-authored-by: Copilot <[email protected]>
Copilot-Session: b24622c7-c9d6-44f0-9a20-85aac5ff11d6
Co-authored-by: Copilot <[email protected]>
Copilot-Session: b24622c7-c9d6-44f0-9a20-85aac5ff11d6
Co-authored-by: Copilot <[email protected]>
Copilot-Session: b24622c7-c9d6-44f0-9a20-85aac5ff11d6
@jevansaks
Jevan Saks (jevansaks) marked this pull request as ready for review August 5, 2026 06:15
Jevan Saks (jevansaks) and others added 2 commits August 7, 2026 13:56
Co-authored-by: Copilot <[email protected]>
Copilot-Session: b24622c7-c9d6-44f0-9a20-85aac5ff11d6
Co-authored-by: Copilot <[email protected]>
Copilot-Session: b24622c7-c9d6-44f0-9a20-85aac5ff11d6
@jevansaks
Jevan Saks (jevansaks) marked this pull request as draft August 8, 2026 00:46
@jevansaks
Jevan Saks (jevansaks) marked this pull request as ready for review August 11, 2026 16:22

@Sergio0694 Sergio Pedri (Sergio0694) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, seems very convenient!

Co-authored-by: Copilot <[email protected]>

Copilot-Session: 3c541bf2-2b33-4212-8c2f-cb19a7af6728
@jevansaks
Jevan Saks (jevansaks) enabled auto-merge (squash) September 1, 2026 22:44
Jesse Stricker (jessestricker) pushed a commit to jessestricker/windows-theme-switcher that referenced this pull request Nov 14, 2026
Updated
[Microsoft.Windows.CsWin32](https://github.com/microsoft/CsWin32) from
0.3.330 to 0.3.371.

<details>
<summary>Release notes</summary>

_Sourced from [Microsoft.Windows.CsWin32's
releases](https://github.com/microsoft/CsWin32/releases)._

## 0.3.371


## Changes:

* #​1878: Initialize out SafeHandles before publishing them
* #​1875: Fix PInvoke017 for span-based string copies in using scopes

This list of changes was [auto
generated](https://devdiv.visualstudio.com/DevDiv/_build/results?buildId=15977588&view=logs).

## 0.3.369


## Changes:

* #​1870: Fix cross-assembly COM projections and shared helpers
* #​1871: Upload consumer-tested NuGet packages from PR builds

This list of changes was [auto
generated](https://devdiv.visualstudio.com/DevDiv/_build/results?buildId=15944789&view=logs).

## 0.3.367


## Changes:

* #​1864: Fix OverflowException for sign-extended handles in SafeHandle
conversions

This list of changes was [auto
generated](https://devdiv.visualstudio.com/DevDiv/_build/results?buildId=15771099&view=logs).

## 0.3.366


## Changes:

* #​1860: Update Win32 metadata to 71.0.37-preview
* #​1859: Generate SafeHandle owners for cleanup functions that return
BOOLEAN
* #​1844: Generate SafeHandle for RAIIFree-annotated parameters, and
make getting the Value from a SafeHandle easier (but still safe)

This list of changes was [auto
generated](https://devdiv.visualstudio.com/DevDiv/_build/results?buildId=15738141&view=logs).

## 0.3.363


## Changes:

* #​1846: Support TypeDefinition handles for struct-typed constants in
nesting and extension blocks
* #​1851: Switch builds to the VSEng-MicroBuildVSStable pool
* #​1850: Fix build-task LibraryImport generation with extensionReceiver
* #​1825: extensionReceiver with CsWin32RunAsBuildTask=true emits
unsupported LibraryImport partials

This list of changes was [auto
generated](https://devdiv.visualstudio.com/DevDiv/_build/results?buildId=15677307&view=logs).

## 0.3.360


## Changes:

* #​1849: Fix custom marshaller namespaces for root metadata types
* #​1848: Flat-namespace native typedef marshallers emit invalid C# in
build-task mode
* #​1828: Fix XML documentation with colliding Win32 ABI types

This list of changes was [auto
generated](https://devdiv.visualstudio.com/DevDiv/_build/results?buildId=15621650&view=logs).

## 0.3.358


## Changes:

* #​1843: Use published Win32 metadata for interior-pointer tests
* #​1840: Keep buffers containing interior pointers as native pointers
* #​1820: Exclude Foundation.Metadata from direct API generation

This list of changes was [auto
generated](https://devdiv.visualstudio.com/DevDiv/_build/results?buildId=15604398&view=logs).

## 0.3.355


## Changes:

* #​1838: Update Win32 metadata to 71.0.28-preview

This list of changes was [auto
generated](https://devdiv.visualstudio.com/DevDiv/_build/results?buildId=15590335&view=logs).

## 0.3.347


## Changes:

* #​1821: Honor configured visibility for IVTable

This list of changes was [auto
generated](https://devdiv.visualstudio.com/DevDiv/_build/results?buildId=15574118&view=logs).

## 0.3.346


## Changes:

* #​1831: Generate safe COM output pointer ABI
* #​1835: Add `CsWin32PlatformTarget` to generate arch-specific APIs in
AnyCPU projects
* #​1807: Update dependency Xunit.Combinatorial to 2.1.41
* #​1817: Update dependency Microsoft.NET.Test.Sdk to 18.10.1 -
autoclosed
* #​1814: Update nbgv and nerdbank.gitversioning updates to 3.10.94
* #​1815: Update dependency powershell to v7.6.6
* #​1811: Update dependency dotnet-coverage to v18.11.2
* #​1816: Update Dockerfile and global.json updates
* #​1823: Update dependency ubuntu to v26
* #​1808: Update actions/deploy-pages action to v5.0.1
<details><summary><b>See More</b></summary>

* #​1824: Update .NET SDK to 10.0.401

This list of changes was [auto
generated](https://devdiv.visualstudio.com/DevDiv/_build/results?buildId=15556629&view=logs).</details>

## 0.3.335


## Changes:

* #​1822: Fix IInspectable-derived COM interface layout
* #​1813: Fix GitHub release service connection

This list of changes was [auto
generated](https://devdiv.visualstudio.com/DevDiv/_build/results?buildId=15400584&view=logs).

## 0.3.333

### Feature Improvements

- **Smarter COM marshalling
([#​1771](microsoft/CsWin32#1771 CsWin32
now automatically marshals recognized COM outputs as WinRT objects when
appropriate.
- **Simpler IID/PPV calls
([#​1720](microsoft/CsWin32#1720 IID and
`void**` parameter pairs now produce generic `<T>` overloads.

Before:

```csharp
shellItem.BindToHandler(pbc, in bhid, typeof(IStream).GUID, out object result);
IStream stream = (IStream)result;
```

After:

```csharp
shellItem.BindToHandler<IStream>(pbc, in bhid, out IStream stream);
```

CsWin32 supplies the IID and returns the strongly typed interface
directly.

## Changes:


### Fixes:


* #​1745: Invalid Code Generated for CsWin32.UI.Accessibility
methods/interfaces/Delegates With `"allowMarshaling": true`
* #​1739: NullReferenceException from passing null as CallbackParam for
MiniDumpWriteDump

### Others:


* #​1812: Make generator path quoting test cross-platform
* #​1810: Preserve coclass generic type fields for AOT
* #​1809: Quote generator tool path in command line
* #​1771: Automatically marshal COM outputs as WinRT
* #​1789: Update dotnet monorepo to 5.9.0
* #​1797: Update dependency nerdbank.dotnetrepotools to v1.5.42
<details><summary><b>See More</b></summary>

* #​1803: Update dependency CSharpIsNullAnalyzer to 0.2.19 - autoclosed
* #​1801: Update dependency Microsoft.Windows.SDK.CPP to 10.0.28000.2705
* #​1800: Update dependency Microsoft.Windows.SDK.BuildTools to
10.0.28000.2705
* #​1788: Update dependency Microsoft.NET.Test.Sdk to 18.9.0
* #​1787: Update dependency powershell to v7.6.5
* #​1782: Update Dockerfile and global.json updates
* #​1786: Qualify special string typedefs (PCWSTR) to
Windows.Win32.Foundation for non-Win32 metadata
* #​1784: Update dependency NuGet.Protocol to 7.9.0
* #​1781: Null-terminate PCSTR friendly overload strings
* #​1775: Generated string-friendly overloads for PCSTR parameters do
not append a null terminator
 ... (truncated)

Commits viewable in [compare
view](https://github.com/microsoft/CsWin32/commits/v0.3.371).
</details>

[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=Microsoft.Windows.CsWin32&package-manager=nuget&previous-version=0.3.330&new-version=0.3.371)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)


</details>

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants