microsoft / microsoft/CsWin32

Friendly overloads of functions with an HDC parameter should accept `SafeHandle`

Open
#1,049 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
2.5k
Forks
124
Avg merge
1d 3h
Merged PRs (30d)
9

Description

EnumDisplayMonitors could before called this way:

Windows.Win32.PInvoke.EnumDisplayMonitors(null, null, proc, 0);

Now the compiler complains:

Argument 1: cannot convert from '' to 'Windows.Win32.Graphics.Gdi.HDC'

I checked the two version and it seems 0.3.18-beta does not create the SafeHandle version anymore (see below the generated code for the two version). Is this a bug or was this intended?

0.2.46-beta

internal static unsafe winmdroot.Foundation.BOOL EnumDisplayMonitors(SafeHandle hdc, winmdroot.Foundation.RECT? lprcClip, winmdroot.Graphics.Gdi.MONITORENUMPROC lpfnEnum, winmdroot.Foundation.LPARAM dwData)

internal static extern unsafe winmdroot.Foundation.BOOL EnumDisplayMonitors(winmdroot.Graphics.Gdi.HDC hdc, [Optional] winmdroot.Foundation.RECT* lprcClip, winmdroot.Graphics.Gdi.MONITORENUMPROC lpfnEnum, winmdroot.Foundation.LPARAM dwData);

0.3.18-beta

internal static unsafe winmdroot.Foundation.BOOL EnumDisplayMonitors(winmdroot.Graphics.Gdi.HDC hdc, winmdroot.Foundation.RECT? lprcClip, winmdroot.Graphics.Gdi.MONITORENUMPROC lpfnEnum, winmdroot.Foundation.LPARAM dwData)

internal static extern unsafe winmdroot.Foundation.BOOL EnumDisplayMonitors(winmdroot.Graphics.Gdi.HDC hdc, [Optional] winmdroot.Foundation.RECT* lprcClip, winmdroot.Graphics.Gdi.MONITORENUMPROC lpfnEnum, winmdroot.Foundation.LPARAM dwData);

Originally posted by @msedi in https://github.com/microsoft/CsWin32/issues/1022#issuecomment-1722834688

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the generator entry point for the EnumDisplayMonitors overloads and compare the generated output described for versions 0.2.46-beta and 0.3.18-beta. Trace how HDC parameters are classified, then locate or add a regression test showing that the friendly overload accepts SafeHandle and permits the null call shown in the issue.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.