Files
mirror-processhacker/1.x/trunk/ProcessHacker.Native/Memory/PinnedObject.cs
T
dmex fd135fbae3 moved all ListView controls to ExtendedListView, fixed some API ref defs, added initial LastError error handling semantics
git-svn-id: svn://svn.code.sf.net/p/processhacker/code@4258 21ef857c-d57f-4fe0-8362-d861dc6d29cd
2011-06-25 12:39:06 +00:00

28 lines
617 B
C#

using System;
using System.Runtime.InteropServices;
namespace ProcessHacker.Native
{
public sealed class PinnedObject<T> : MemoryRegion
{
private GCHandle _handle;
public T Object { get; private set; }
public PinnedObject(T obj)
{
this.Object = obj;
_handle = GCHandle.Alloc(obj, GCHandleType.Pinned);
}
protected override void Free()
{
this._handle.Free();
}
public IntPtr Address
{
get { return _handle.AddrOfPinnedObject(); }
}
}
}