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

Automatically marshal COM outputs as WinRT#1771
Jevan Saks (jevansaks) merged 12 commits into
mainfrom
user/jevansa/com-out-ptr-marshalling-policy

Conversation

@jevansaks

@jevansaksJevan 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 <223556219+Copilot@users.noreply.github.com>
Copilot-Session: b24622c7-c9d6-44f0-9a20-85aac5ff11d6
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: b24622c7-c9d6-44f0-9a20-85aac5ff11d6
@jevansaks

Copy link
Copy Markdown
MemberAuthor

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 <223556219+Copilot@users.noreply.github.com>
Copilot-Session: b24622c7-c9d6-44f0-9a20-85aac5ff11d6
@jevansaksJevan Saks (jevansaks) changed the title Add COM output pointer marshalling policiesAutomatically marshal COM outputs as WinRTJul 31, 2026
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: b24622c7-c9d6-44f0-9a20-85aac5ff11d6
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: b24622c7-c9d6-44f0-9a20-85aac5ff11d6
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: b24622c7-c9d6-44f0-9a20-85aac5ff11d6
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: b24622c7-c9d6-44f0-9a20-85aac5ff11d6
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: b24622c7-c9d6-44f0-9a20-85aac5ff11d6
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: b24622c7-c9d6-44f0-9a20-85aac5ff11d6
@jevansaks
Jevan Saks (jevansaks) marked this pull request as ready for review August 5, 2026 06:15
Comment threadsrc/Microsoft.Windows.CsWin32/templates/ComOrWinRTObjectMarshaller.cs Outdated
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: b24622c7-c9d6-44f0-9a20-85aac5ff11d6
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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

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!

Comment threadtest/Microsoft.Windows.CsWin32.Tests/COMTests.cs Outdated
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 3c541bf2-2b33-4212-8c2f-cb19a7af6728
This was referenced Sep 4, 2026
Sign up for freeto 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

@jevansaks@Sergio0694