mirror of
https://github.com/mirror/processhacker
synced 2026-06-08 16:03:24 +00:00
42a383a530
git-svn-id: svn://svn.code.sf.net/p/processhacker/code@3598 21ef857c-d57f-4fe0-8362-d861dc6d29cd
36 lines
1.1 KiB
C#
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;
|
|
}
|
|
}
|
|
}
|
|
}
|