Friendly overloads of functions with an HDC parameter should accept `SafeHandle`
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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