Repository navigation
Fix providing EnhancedMetafile to other applications through the clip… - #11988
Open
justinswork wants to merge 1 commit into
Open
justinswork wants to merge 1 commit into
justinswork wants to merge 1 commit into
Conversation
…board The shared OLE code in System.Private.Windows.Core only accepts TYMED_HGLOBAL, TYMED_ISTREAM and TYMED_GDI, so every request for CF_ENHMETAFILE (always TYMED_ENHMF) fails before WPF's handler runs. - Add WpfOleServices.AllowedTymeds, which also allows TYMED_ENHMF. It implements IOleServices.AllowedTymeds once the companion dotnet/winforms change flows in, and must be in place before then. - Fix the TYMED_ENHMF branch of WpfOleServices.GetDataHere, which never assigned the handle created from a MemoryStream and returned S_OK with a null handle. It now sets tymed and hEnhMetaFile, and returns E_FAIL when there is no handle, as .NET 9 did. - Add a clipboard test that reads the EMF back the way another application would. It is skipped until the winforms change flows in. Fixes dotnet#11986 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Non-publicly-visible MemoryStream buffers still throw during enhanced-metafile retrieval.
Review effort: Balanced
Findings: 1
Open (1)
What changed in this PR
Restores WPF enhanced-metafile clipboard interoperability on newer .NET versions.
Changes:
- Allows
TYMED_ENHMFin WPF OLE services. - Correctly populates enhanced-metafile storage media.
- Adds native clipboard interoperability coverage.
| File | Description |
|---|---|
WpfOleServices.cs |
Enables and returns enhanced-metafile handles. |
ClipboardTests.cs |
Tests native retrieval of clipboard EMF data. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Author
|
May be implemented by #12036 instead, although this seems like a simpler, more targeted solution in my opinion |
Shyam-Gupta
added a commit
to dotnet/winforms
that referenced
this pull request
Oct 28, 2026
…nhanced metafiles (#15218) Fixes dotnet/wpf#11986 Companion WPF PR: dotnet/wpf#11988 ## Proposed changes - Add `IOleServices.AllowedTymeds`, following the existing `#if NET static abstract` pattern. - `Composition` reads the allowed media types from the platform instead of the hard-coded `TYMED_HGLOBAL | TYMED_ISTREAM | TYMED_GDI`, in both the managed-to-native and native-to-managed adapters. - `WinFormsOleServices` returns the old value, so WinForms behavior is unchanged. WPF adds `TYMED_ENHMF` in the companion PR. ## Customer Impact - On .NET 10, WPF apps can't provide `CF_ENHMETAFILE` to other applications: every `TYMED_ENHMF` request fails with `DV_E_TYMED` before WPF's handler runs. Pasting EMF into apps like Word fails silently, with no workaround. ## Regression? - Yes. .NET 9 WPF allowed `TYMED_ENHMF`, and the shared mask dropped it. ## Risk - Low. WinForms gets the same value as before, and `IOleServices` is internal. - The value is per platform rather than added to the shared constant, because WinForms can't supply or read EMF. A shared value would make WinForms report EMF as available when it isn't. ## Test methodology - Added `ManagedToNativeAdapterTests`, which fails with `DV_E_TYMED` without this change. - `System.Private.Windows.Core.Tests` passes on net11.0 and net481. - Validated end-to-end with a WPF app on .NET 11 RC 1, using WPF built with the companion change: EMF paste now works for delayed and flushed data. ## Test environment(s) - .NET SDK 11.0.100-rc.1.26420.103, Windows 11 (10.0.26200) ###### Microsoft Reviewers: [Open in CodeFlow](https://microsoft.github.io/open-pr/?codeflow=https://github.com/dotnet/winforms/pull/15218)
Shyam-Gupta
approved these changes
Oct 28, 2026
Member
|
@dipeshmsft, @pranav-gupta-msft, @subhajitm - We validated this change and didn't find any regressions. Could you please review this PR? Also we plan to take it for servicing in 10.0 and 11.0 release. Thanks. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Fixes #11986
Depends on dotnet/winforms#15218.
This PR has to merge before that change flows into WPF, or WPF won't build.
Description
On .NET 10, the shared OLE code in System.Private.Windows.Core rejects every
TYMED_ENHMFrequest withDV_E_TYMED, so WPF can't provideCF_ENHMETAFILEto other applications even though the format is still advertised.WpfOleServices.AllowedTymeds, which also allowsTYMED_ENHMF. It implements the newIOleServices.AllowedTymedsfrom dotnet/winforms#TBD.TYMED_ENHMFbranch ofWpfOleServices.GetDataHere, which was unreachable until now. For aMemoryStreamit never assigned the handle to the medium, so it returnedS_OKwith a null handle. It now setstymedandhEnhMetaFile, and returnsE_FAILwhen there is no handle, as .NET 9 did.GetClipboardData, the way another application would. It's skipped until the winforms change flows in.I'd like to request a backport to
release/10.0after this merges.Customer Impact
EMF that WPF apps put on the clipboard can't be pasted into other applications, for example Word's Paste Special → Picture (Enhanced Metafile). It fails silently, and there's no workaround.
Regression
Yes. It works on .NET 9 and is broken on .NET 10.
Testing
build.cmd -packsucceeds, both against the currentMicrosoft.Private.Winformspackage and against a local build of Let each platform declare the TYMEDs it supports so WPF can provide enhanced metafiles winforms#15218.copy: trueandcopy: false.GetClipboardData(CF_ENHMETAFILE)and OLEGetData, for delayed and flushed data. The unpatched runtime fails all three checks.Risk
Low. It only affects
TYMED_ENHMFrequests forEnhancedMetafiledata, which always fail today, and restores the .NET 9 behavior.