Skip to content

Update CsWin32 to 0.3.287 and remove .NET Framework IComIID workarounds#14639

Open
JeremyKuhne wants to merge 2 commits into
dotnet:mainfrom
JeremyKuhne:update-cswin32-0.3.287
Open

Update CsWin32 to 0.3.287 and remove .NET Framework IComIID workarounds#14639
JeremyKuhne wants to merge 2 commits into
dotnet:mainfrom
JeremyKuhne:update-cswin32-0.3.287

Conversation

@JeremyKuhne

@JeremyKuhne JeremyKuhne commented Jun 11, 2026

Copy link
Copy Markdown
Member

Summary

Updates Microsoft.Windows.CsWin32 from 0.3.151 to 0.3.287 and removes the manual IComIID workarounds we maintained for .NET Framework.

CsWin32 0.3.287 now emits the IComIID interface for net472 / netstandard2.0 (see microsoft/CsWin32#1704). Previously it only generated IComIID for modern .NET, which is why we hand-authored the interface and appended : IComIID to each COM struct under the Framework folder. Those workarounds are now redundant.

Changes

Core request

  • Bump MicrosoftWindowsCsWin32PackageVersion 0.3.1510.3.287.
  • Delete the manual IComIID interface definition and the 12 COM struct partials under System.Private.Windows.Core/src/Framework/Windows/Win32/ that implemented it. The shared IID.cs already 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)

  • Optional out-pointer parameters are now out (WideCharToMultiByte, SHParseDisplayName, get_accHelpTopic, DrawThemeEdge, GetThemeBackgroundRegion).
  • DocumentProperties now takes PRINTER_HANDLE instead of HANDLE.
  • Some buffer methods lost their string-friendly overloads; pin strings and pass PCWSTR (GetThemeDocumentationProperty, RegLoadMUIString, GetShortPathName, GetLocaleInfoEx).
  • DrawFrameControl dropped its DFC_TYPE / DFCS_STATE enums (now uint). Re-requested both enums in NativeMethods.txt so the public ButtonState / ScrollButton enum values are preserved, and added (uint) casts at call sites.
  • Suppressed new CLS-compliance warnings on generated COM structs (CS3021 in the Core projects, CS3019 in Primitives), grouped with the existing CS3016 suppression.
  • Updated XML doc 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

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
@JeremyKuhne JeremyKuhne requested a review from a team as a code owner June 11, 2026 17:28
@JeremyKuhne JeremyKuhne changed the title Update CsWin32 to 0.3.287 and remove .NET Framework IComIID hacks Update CsWin32 to 0.3.287 and remove .NET Framework IComIID workarounds Jun 11, 2026
{
// Get Win32 dc with Graphics properties applied to it.
PInvoke.DrawFrameControl(hdc, ref rcFrame, kind, state);
PInvoke.DrawFrameControl(hdc, ref rcFrame, (uint)kind, (uint)state);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

FYI if DrawFrameControl only takes DFC_TYPE / DFC_STATE for these parameters, that type improvement (uint => DFC_TYPE) can be done in win32metadata. Feel free to file an issue on win32metadata to recommend that.

<NoWarn>$(NoWarn);CS8981;CS3016</NoWarn>
<!--
We don't care about CLS compliance since everything here is internal and we want to match native types.
CS3019: CsWin32-generated COM structs carry [CLSCompliant] attributes on internal (non-visible) types.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Wait, did that CLSCompliant change now cause us to trigger a CS3019 on callers? Or is this only going to happen when you make the projection public ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This happens when internal, not public. I could suppress this error as well in the generated code if you like.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Yes, please do that. I approved it because I assumed the attribute wouldn't matter to folks who don't care about CLSCompliant. I don't want noise for people. None of my code cares about CLS.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'll create a PR that hits all of the corners of this.

Comment thread src/System.Windows.Forms/System/Windows/Forms/Help/Help.cs
Shyam-Gupta
Shyam-Gupta previously approved these changes Jun 11, 2026

@Shyam-Gupta Shyam-Gupta 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.

:shipit: Looks good. Thanks Jeremy.

@KlausLoeffelmann KlausLoeffelmann 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.

I would like to know more first about the motivation behind this, and why we need to do this now.

@dotnet-policy-service dotnet-policy-service Bot added the waiting-author-feedback The team requires more information from the author label Jun 11, 2026
@KlausLoeffelmann

KlausLoeffelmann commented Jun 11, 2026

Copy link
Copy Markdown
Member

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.
@dotnet-policy-service dotnet-policy-service Bot removed the waiting-author-feedback The team requires more information from the author label Jun 11, 2026
@JeremyKuhne

Copy link
Copy Markdown
Member Author

@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.

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.

4 participants