using System.Diagnostics.CodeAnalysis; using System.Runtime.InteropServices; namespace AutoAgent.Domain.Models { public class MemoryBuffer : IDisposable { private IntPtr _memory; public IntPtr SetStruct([DisallowNull] T value, bool fDeleteOld = true) { Marshal.StructureToPtr(value, _memory, true); return _memory; } public MemoryBuffer(int size) { _memory = Marshal.AllocHGlobal(User32Dll.INPUT_SIZE); } public void Dispose() { if (_memory != IntPtr.Zero) { Marshal.FreeHGlobal(_memory); _memory = IntPtr.Zero; } } } }