Repository navigation
Update CsWin32 to 0.3.287 and remove .NET Framework IComIID workarounds - #14639
Conversation
CsWin32 0.3.287 now emits the IComIID interface for net472/netstandard2.0 (microsoft/CsWin32#1704), so the manual definitions and per-struct implementations we maintained for .NET Framework are no longer needed. - Bump MicrosoftWindowsCsWin32PackageVersion 0.3.151 -> 0.3.287 - Delete the manual IComIID interface and the 12 COM struct partials under System.Private.Windows.Core/src/Framework that appended : IComIID Adapt to generated-signature changes from the version bump: - Optional out-pointer params are now 'out' (WideCharToMultiByte, SHParseDisplayName, get_accHelpTopic, DrawThemeEdge, GetThemeBackgroundRegion) - DocumentProperties now takes PRINTER_HANDLE - Buffer methods lost string-friendly overloads; pin strings for PCWSTR - Re-request DFC_TYPE/DFCS_STATE in NativeMethods.txt (DrawFrameControl now takes uint) so public ButtonState/ScrollButton enum values are preserved - Suppress new CLS warnings on generated COM structs (CS3021/CS3019) - Update XML doc crefs to match new signatures
Shyam-Gupta
left a comment
There was a problem hiding this comment.
Looks good. Thanks Jeremy.
KlausLoeffelmann
left a comment
There was a problem hiding this comment.
I would like to know more first about the motivation behind this, and why we need to do this now.
|
This is not a good point in time to take this PR, as I am really busy to introduce a series of APIs for .NET 11. @JeremyKuhne, next time you plan a change like that, I'd like you to check with me first. Can this PR wait until after we merged for .NET 11? Is this a PR that is immediately needed for an initiative I would not know about which this cannot wait? Let me see, if I can find the time, to quickly rebase to PRs I got on this and see, if they are in any way affected by this. @merriemcgaw , @mcastro-x FYI. |
…overloads - WideCharToMultiByte/SHParseDisplayName: omit the optional out param instead of passing 'out _' so the call truly passes null (out _ is not equivalent to null). - GetShortPathName (Help.cs): use the friendly Span<char> overload, removing manual pinning. RegLoadMUIString is intentionally left on the raw overload: its friendly Span overload passes the char count as cbOutBuf, which the API documents as a byte count, so it would misreport the buffer size.
|
@KlausLoeffelmann you do not need to review if you're too busy, @Shyam-Gupta has signed up for this. This is a low impact change that applies follow up changes upstream to changes in this and other repos. |
There was a problem hiding this comment.
Pull request overview
Updates the repo’s CsWin32-generated interop layer to Microsoft.Windows.CsWin32 0.3.287, removing now-redundant .NET Framework IComIID workarounds and adjusting call sites/docs/projects to match the new generated signatures and types.
Changes:
- Bump
Microsoft.Windows.CsWin32package version and adjust call sites for updated P/Invoke signatures (e.g.,outparameters, removed optional params,PCWSTRusage,uint-typed enums). - Remove hand-authored
.NET FrameworkIComIIDinterface and related COM struct partials undersrc/System.Private.Windows.Core/src/Framework/Windows/Win32/. - Update project warning suppressions and documentation
crefs impacted by the generator changes.
Reviewed changes
Copilot reviewed 33 out of 33 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/System.Windows.Forms/System/Windows/Forms/VisualStyles/VisualStyleRenderer.cs | Updates theming P/Invoke calls to use out parameters. |
| src/System.Windows.Forms/System/Windows/Forms/Rendering/ControlPaint.cs | Adjusts DrawFrameControl calls to match uint signature. |
| src/System.Windows.Forms/System/Windows/Forms/Printing/PrinterSettingsExtensions.cs | Updates DocumentProperties handle type to PRINTER_HANDLE. |
| src/System.Windows.Forms/System/Windows/Forms/Printing/PageSetupDialog.cs | Updates GetLocaleInfoEx call site for new parameter type. |
| src/System.Windows.Forms/System/Windows/Forms/Help/Help.cs | Updates GetShortPathName usage for new overloads (has a behavioral bug—see comment). |
| src/System.Windows.Forms/System/Windows/Forms/Controls/DataGridView/DataGridViewCheckBoxCell.cs | Updates DrawFrameControl usage to match new uint signature. |
| src/System.Windows.Forms/System/Windows/Forms/Controls/Buttons/ButtonInternal/CheckBoxBaseAdapter.cs | Updates DrawFrameControl usage to match new uint signature. |
| src/System.Windows.Forms/System/Windows/Forms/Accessibility/AccessibleObjectExtensions.cs | Updates get_accHelpTopic call to new out pattern. |
| src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Shell32/ShellItemTests.cs | Updates test for SHParseDisplayName signature change. |
| src/System.Windows.Forms.Primitives/src/Windows/Win32/PInvoke.SHCreateShellItem.cs | Updates helper to match SHParseDisplayName signature change. |
| src/System.Windows.Forms.Primitives/src/Windows/Win32/Pinvoke.RegLoadMUIString.cs | Pins and passes PCWSTR for updated RegLoadMUIString signature; updates cref. |
| src/System.Windows.Forms.Primitives/src/Windows/Win32/PInvoke.GetThemeDocumentationProperty.cs | Pins strings and passes PCWSTR for updated signature. |
| src/System.Windows.Forms.Primitives/src/System.Windows.Forms.Primitives.csproj | Adds CS3019 suppression for new generator-emitted CLS attributes. |
| src/System.Windows.Forms.Primitives/src/NativeMethods.txt | Requests DFC_TYPE / DFCS_STATE enums to preserve typed usage. |
| src/System.Windows.Forms.Primitives/src/Microsoft/VisualStudio/Shell/IVsPerPropertyBrowsing.cs | Updates XML doc cref to match signature changes. |
| src/System.Private.Windows.Core/src/System/Private/Windows/Ole/Composition.ManagedToNativeAdapter.cs | Updates WideCharToMultiByte calls for signature change. |
| src/System.Private.Windows.Core/src/System.Private.Windows.Core.csproj | Adds CS3021 suppression for new generator-emitted CLS attributes. |
| src/System.Private.Windows.Core/src/Microsoft.Private.Windows.Core.csproj | Adds CS3021 suppression for new generator-emitted CLS attributes. |
| src/System.Private.Windows.Core/src/Framework/Windows/Win32/UI/Shell/IDropTargetHelper.cs | Removes now-redundant IComIID partial workaround. |
| src/System.Private.Windows.Core/src/Framework/Windows/Win32/UI/Shell/IDragSourceHelper2.cs | Removes now-redundant IComIID partial workaround. |
| src/System.Private.Windows.Core/src/Framework/Windows/Win32/System/Ole/IDropTarget.cs | Removes now-redundant IComIID partial workaround. |
| src/System.Private.Windows.Core/src/Framework/Windows/Win32/System/Com/IUnknown.cs | Removes now-redundant IComIID partial workaround. |
| src/System.Private.Windows.Core/src/Framework/Windows/Win32/System/Com/ITypeLib.cs | Removes now-redundant IComIID partial workaround. |
| src/System.Private.Windows.Core/src/Framework/Windows/Win32/System/Com/ITypeInfo.cs | Removes now-redundant IComIID partial workaround. |
| src/System.Private.Windows.Core/src/Framework/Windows/Win32/System/Com/IStream.cs | Removes now-redundant IComIID partial workaround. |
| src/System.Private.Windows.Core/src/Framework/Windows/Win32/System/Com/IGlobalInterfaceTable.cs | Removes now-redundant IComIID partial workaround. |
| src/System.Private.Windows.Core/src/Framework/Windows/Win32/System/Com/IEnumSTATDATA.cs | Removes now-redundant IComIID partial workaround. |
| src/System.Private.Windows.Core/src/Framework/Windows/Win32/System/Com/IEnumFORMATETC.cs | Removes now-redundant IComIID partial workaround. |
| src/System.Private.Windows.Core/src/Framework/Windows/Win32/System/Com/IDataObject.cs | Removes now-redundant IComIID partial workaround. |
| src/System.Private.Windows.Core/src/Framework/Windows/Win32/System/Com/IAdviseSink.cs | Removes now-redundant IComIID partial workaround. |
| src/System.Private.Windows.Core/src/Framework/Windows/Win32/IComIID.cs | Removes now-redundant manual IComIID interface. |
| src/System.Drawing.Common/src/System/Drawing/Printing/PageSettings.cs | Updates DocumentProperties handle type to PRINTER_HANDLE. |
| eng/Versions.props | Bumps MicrosoftWindowsCsWin32PackageVersion to 0.3.287. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
|
Ah, sorry @JeremyKuhne for the delay. Can you take a look? |
|
I (Copilot.Cli) took a quick look at the failing build on behalf of Klaus. This looks deterministic rather than intermittent: the build is failing on a syntax error in I opened a tiny support PR against your incoming branch here: JeremyKuhne#1 That PR is meant purely as support help; no problem at all to dismiss it if it takes the wrong approach or if you already have another fix in mind. |
The autofix that added the 'if (written > 0)' guard around the short-path assignment dropped the closing brace of the 'if (requiredStringSize > 0)' block, producing CS1513 and breaking all build legs. Restore the brace, keeping the behavioral guard.
I don't know why CoPilot messed up the brackets, I've put up a fix and it appears to be passing now. |
KlausLoeffelmann
left a comment
There was a problem hiding this comment.
Thanks everyone, and sorry for the delay!
Just for background (and I will also make sure, I communicate that better to you guys in the future!):
Both @JeremyKuhne and I have been bitten by the amount of necessary refactoring effort at times, which can be introduced by updating CsWin32 versions.
I am in the last phase in my schedule to introduce new APIs for WinForms in .NET 11 - which also heavily rely on CsWin32. So, I needed to make sure first, the update does not badly break me.
Just want to make sure:
@jevansaks, I was at your talk when you introduced your effort to us, and we spoke during the session and after, so you know, how hyped and excited I was about that. I feel I need to emphasize to the both of you, that I know your work has SUPER high priority.
Will reach out when it gets a bit sorted out with release dates the next weeks, to offer more of support over internal channels!
If something like this comes up again, and if it is possible in any way for you, try to give me a short heads up, and I will immediately reprioritize other tasks over this!
@merriemcgaw, @mcastro-x, @Shyam-Gupta FYI.
Summary
Updates
Microsoft.Windows.CsWin32from0.3.151to0.3.287and removes the manualIComIIDworkarounds we maintained for .NET Framework.CsWin32 0.3.287 now emits the
IComIIDinterface fornet472/netstandard2.0(see microsoft/CsWin32#1704). Previously it only generatedIComIIDfor modern .NET, which is why we hand-authored the interface and appended: IComIIDto each COM struct under theFrameworkfolder. Those workarounds are now redundant.Changes
Core request
MicrosoftWindowsCsWin32PackageVersion0.3.151→0.3.287.IComIIDinterface definition and the 12 COM struct partials underSystem.Private.Windows.Core/src/Framework/Windows/Win32/that implemented it. The sharedIID.csalready handles the static-vs-instance difference via#if NET, so it needs no change.Fallout from the version bump (required to keep the solution building)
out(WideCharToMultiByte,SHParseDisplayName,get_accHelpTopic,DrawThemeEdge,GetThemeBackgroundRegion).DocumentPropertiesnow takesPRINTER_HANDLEinstead ofHANDLE.string-friendly overloads; pin strings and passPCWSTR(GetThemeDocumentationProperty,RegLoadMUIString,GetShortPathName,GetLocaleInfoEx).DrawFrameControldropped itsDFC_TYPE/DFCS_STATEenums (nowuint). Re-requested both enums inNativeMethods.txtso the publicButtonState/ScrollButtonenum values are preserved, and added(uint)casts at call sites.CS3021in the Core projects,CS3019in Primitives), grouped with the existingCS3016suppression.crefs that referenced changed signatures.Validation
Clean rebuild of the full solution (
dotnet build Winforms.sln -t:Rebuild -p:TreatWarningsAsErrors=true) succeeds with 0 errors and 0 warnings across all src, facade, analyzer, source-generator, and test projects.Microsoft Reviewers: Open in CodeFlow