dahall / Vanara

A set of .NET libraries for Windows implementing PInvoke calls to many native Windows APIs with supporting wrappers.
MIT License
1.81k stars 196 forks source link

Shell32.IDesktopWallpaper.SetWallpaper should return HRESULT instead of void #397

Closed zhuxb711 closed 1 year ago

zhuxb711 commented 1 year ago

Describe the bug and how to reproduce

Incorrect:

void SetWallpaper([MarshalAs(UnmanagedType.LPWStr)] string monitorID, [MarshalAs(UnmanagedType.LPWStr)] string wallpaper);

Correct:

HRESULT SetWallpaper([MarshalAs(UnmanagedType.LPWStr)] string monitorID, [MarshalAs(UnmanagedType.LPWStr)] string wallpaper);
dahall commented 1 year ago

For almost all of the COM interfaces, I have removed the [PreserveSig] attribute and changed the return value to void when the return value does not return any information beyond an error or when the final parameter can be used as a return value and a non-exception return is needed to adjust input memory allocations. If just an error, C# converts the HRESULT to the equivalent Exception.

dahall commented 1 year ago

If I set this one differently, then I really should go and do that for the hundreds of other interfaces with potentially thousands of methods to review and change.

zhuxb711 commented 1 year ago

Ok, got it