rodrigocfd / winsafe

Windows API and GUI in safe, idiomatic Rust.
https://crates.io/crates/winsafe
MIT License
520 stars 30 forks source link

Optional Parameters in API Bindings #136

Closed yu-d closed 3 months ago

yu-d commented 3 months ago

Hello,

I recently noticed an inconsistency in the winsafe library regarding parameter types for certain functions. Specifically, the ValidateRect function documentation indicates that the RECT parameter can be NULL, but the winsafe implementation requires a RECT type.

Using ILSpy to examine the .winmd file, I found that the ValidateRect definition includes the [Optional] attribute for parameters:

[DllImport("USER32.dll", ExactSpelling = true, PreserveSig = false)]
[SupportedOSPlatform("windows5.0")]
[Documentation("https://learn.microsoft.com/windows/win32/api/winuser/nf-winuser-validaterect")]
public unsafe static extern BOOL ValidateRect([Optional][In] HWND hWnd, [Optional][In][Const] RECT* lpRect);

There are many other APIs with parameters marked as [Optional] that do not correspondingly use Option in winsafe. Correcting these bindings might be a considerable task.

Could you please let me know if there are any plans to address this issue? Thank you for your hard work and effort on maintaining this library.

Thank you very much!

rodrigocfd commented 3 months ago

ValidateRect is fixed.

Feel free to fill an issue with any other APIs you find, I'm interested.