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.07k stars 87 forks source link

Support [RAIIFree] on output parameters #1078

Open AArnott opened 11 months ago

AArnott commented 11 months ago

Actual behavior

Given the following metadata definition of WlanOpenHandle:

public unsafe static extern uint WlanOpenHandle([In] uint dwClientVersion, [Optional][Reserved] void* pReserved, [Out] uint* pdwNegotiatedVersion, [Out][RAIIFree("WlanCloseHandle")] HANDLE* phClientHandle);

CsWin32 generates the following friendly overload:

internal static unsafe uint WlanOpenHandle(uint dwClientVersion, out uint pdwNegotiatedVersion, winmdroot.Foundation.HANDLE* phClientHandle)

Expected behavior

I expect the last parameter to be an out SafeHandle-derived type that calls WlanCloseHandle when released.