<PackageReference Include="System.Drawing.Common" Version="10.0.0-preview.4.25258.110" />

Lifetime<TVTable, TObject>

Struct that handles managed object COM projection lifetime management.
using System; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Threading; namespace Windows.Win32.System.Com { internal struct Lifetime<[IsUnmanaged] TVTable, [Nullable(2)] TObject> where TVTable : struct { private unsafe TVTable* _vtable; private unsafe void* _handle; private uint _refCount; public unsafe static uint AddRef(void* this) { return Interlocked.Increment(ref ((Lifetime<TVTable, TObject>*)this)->_refCount); } public unsafe static uint Release(void* this) { uint num = Interlocked.Decrement(ref ((Lifetime<TVTable, TObject>*)this)->_refCount); if (num == 0) { GCHandle.FromIntPtr((IntPtr)((Lifetime<TVTable, TObject>*)this)->_handle).Free(); Marshal.FreeCoTaskMem((IntPtr)this); } return num; } [return: Nullable(new byte[] { 0, 0, 0, 1 })] public unsafe static Lifetime<TVTable, TObject>* Allocate([Nullable(1)] TObject object, TVTable* vtable) { Lifetime<TVTable, TObject>* ptr = (Lifetime<TVTable, TObject>*)(long)Marshal.AllocCoTaskMem(sizeof(Lifetime<TVTable, TObject>)); ptr->_vtable = vtable; ptr->_handle = (void*)(long)GCHandle.ToIntPtr(GCHandle.Alloc(object)); ptr->_refCount = 1; return ptr; } [return: Nullable(2)] public unsafe static TObject GetObject(void* this) { get; } } }