win32-automation-agent/Domain/Models/MemoryBuffer.cs

31 lines
726 B
C#
Raw Normal View History

2026-01-08 21:33:01 +03:00
using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
namespace AutoAgent.Domain.Models
{
public class MemoryBuffer : IDisposable
{
private IntPtr _memory;
public IntPtr SetStruct<T>([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;
}
}
}
}