31 lines
726 B
C#
31 lines
726 B
C#
|
|
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;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|