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
2.05k stars 85 forks source link

Allow explicitly specifying A/W API variants #962

Closed JeremyKuhne closed 1 year ago

JeremyKuhne commented 1 year ago

Is your feature request related to a problem? Please describe. In some cases WinForms needs to access both the ASCII and the Unicode variants of APIs. This isn't currently possible afaik. One example of where this comes up with handling message pumping to/from Windows that are in ASCII mode.

Describe the solution you'd like Allow fully specifying A/W APIs when needed. I'm fine if this is behind a configuration switch.

Describe alternatives you've considered We can, and do, manually define the PInvokes in these cases. Would rather not though. :)

Additional context A bit by Raymond Chen on the topic: If the prototypes of DispatchMessageA and DispatchMessageW are identical, why have both?

775 is another case where we have to manually define things.

AArnott commented 1 year ago

CsWin32 already supports this: image

Just set "wideCharOnly": false in the NativeMethods.json file. It will still default to giving you the W methods, but instead of suppressing the suffix, it will retain the suffix (in all cases), allowing you to specifically ask for the A suffixed methods.