Files
mirror-processhacker/2.x/trunk/plugins/ProcessHacker2.Api/ProcessHacker/CallbackRegistration.cs
T
wj32 42a383a530 expanded ProcessHacker2.Api library
git-svn-id: svn://svn.code.sf.net/p/processhacker/code@3598 21ef857c-d57f-4fe0-8362-d861dc6d29cd
2010-09-11 11:16:00 +00:00

36 lines
1.1 KiB
C#

using System;
using System.Runtime.InteropServices;
namespace ProcessHacker2.Api
{
public unsafe class CallbackRegistration : IDisposable
{
private PhCallback* _callback;
private PhCallbackRegistration* _registration;
private PhCallbackFunction _function;
private IntPtr _functionNative;
public CallbackRegistration(PhCallback* callback, PhCallbackFunction function)
{
_callback = callback;
_function = function;
_registration = (PhCallbackRegistration*)Marshal.AllocHGlobal(Marshal.SizeOf(typeof(PhCallbackRegistration)));
_functionNative = Marshal.GetFunctionPointerForDelegate(function);
NativeApi.PhRegisterCallback(_callback, _functionNative, IntPtr.Zero, _registration);
}
public void Dispose()
{
if (_registration != null)
{
NativeApi.PhUnregisterCallback(_callback, _registration);
Marshal.FreeHGlobal((IntPtr)_registration);
_registration = null;
}
}
}
}