microsoft / CsWin32

A source generator to add a user-defined set of Win32 P/Invoke methods and supporting types to a C# project.
MIT License
1.99k stars 84 forks source link

Consider adding PCWSTR.Null #1067

Closed riverar closed 8 months ago

riverar commented 8 months ago

GetModuleHandle has two overloads

Passing in a null creates overload ambiguity and therefore cannot be used.

Similar to https://github.com/microsoft/CsWin32/issues/639

This might be a moot request if the overloads are reduced as a result of resolving https://github.com/microsoft/CsWin32/issues/1068

AArnott commented 8 months ago

As a workaround for now, please use (string)null as the argument.

AArnott commented 8 months ago

or (PCWSTR)null, if you don't want the SafeHandle return type.

AArnott commented 8 months ago

Given the ease of resolving the ambiguity, and that such ambiguities may appear in many other APIs, often unrelated to PCWSTR, and C# developers tend to know how to resolve them, I'm inclined to Won't Fix this to avoid adding APIs when existing solutions exist. Thoughts?

riverar commented 8 months ago

I'm okay with closure, no ill feelings.

C# developers tend to know how to resolve them

I would gently push back on this and say in my decades of writing C#, I never actually hit this scenario. I think the .NET API team very carefully and cleverly avoided creating API overloads like this.