You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
AlsoUsableForAttribute should drive handle struct conversions and SafeHandle overloads #205
Using CsWin32 0.1.422-beta, not referencing the metadata package directly.
This seems to be the required workaround:
// Leaving out DangerousAddRef etc which should generally be added reflexively whenever DangerousGetHandle is usedPInvoke.SelectObject(bitmapDC,(HGDIOBJ)bitmap.DangerousGetHandle());
I'd expect DangerousGetHandle management to be done for me:
PInvoke.SelectObject(bitmapDC,bitmap);
bitmap is a DeleteObjectSafeHandle field that is assigned from a call to CreateDIBSection.
CreateDIBSection returns HBITMAP which is freeable via DeleteObject, so CreateDIBSection offers a SafeHandle.
HGDIOBJ is not a releasable handle, per the metadata. That's why we don't expose a SafeHandle overload of this method.
With the next metadata update, HGDIOBJ will be recognized as a kind of base type for several other typedef structs, including HBITMAP. At that point we should make some changes in the CsWin32 projection to not only add conversion operators between these structs, but also to accept SafeHandle everywhere that accepts HGDIOBJ.
changed the title [-]SelectObject doesn't allow passing a SafeHandle to the HGDIOBJ parameter[/-][+]AlsoUsableForAttribute should drive handle struct conversions and SafeHandle overloads[/+]on Mar 17, 2021
Activity
AArnott commentedon Mar 17, 2021
CreateDIBSectionreturnsHBITMAPwhich is freeable viaDeleteObject, soCreateDIBSectionoffers aSafeHandle.HGDIOBJis not a releasable handle, per the metadata. That's why we don't expose a SafeHandle overload of this method.With the next metadata update,
HGDIOBJwill be recognized as a kind of base type for several other typedef structs, includingHBITMAP. At that point we should make some changes in the CsWin32 projection to not only add conversion operators between these structs, but also to acceptSafeHandleeverywhere that acceptsHGDIOBJ.[-]SelectObject doesn't allow passing a SafeHandle to the HGDIOBJ parameter[/-][+]AlsoUsableForAttribute should drive handle struct conversions and SafeHandle overloads[/+]AArnott commentedon Mar 17, 2021
Duplicate of #199
AlsoUsableForAttributefor more interoperable typedefs #199Bump dotnet-coverage from 17.7.0 to 17.7.1 (#205)