public static void RemoveEvent(EventHandle eventHandle) { if (eventHandle == null) throw new ArgumentNullException("eventHandle"); MirandaPluginLink link = MirandaContext.Current.PluginLink; if (eventHandle.MirandaHandle != IntPtr.Zero) { int result; if ((result = link.NativePluginLink.DestroyHookableEvent(eventHandle.MirandaHandle)) != 0) throw new MirandaException(String.Format(TextResources.ExceptionMsg_Formatable2_MirandaServiceReturnedFailure, "DestroyHookableEvent", result.ToString())); eventHandle.MirandaHandle = IntPtr.Zero; EventHandleCollection handles = eventHandle.Owner.Descriptor.EventHandles; try { SynchronizationHelper.BeginCollectionUpdate(handles); handles.Remove(eventHandle); } finally { SynchronizationHelper.EndUpdate(handles); } } }
public static EventHandle CreateEvent(string eventName, MirandaPlugin owner, Callback defaultSubscriber) { if (String.IsNullOrEmpty(eventName)) throw new ArgumentNullException("eventName"); if (owner == null) throw new ArgumentNullException("owner"); if (!owner.Initialized) throw new InvalidOperationException(TextResources.ExceptionMsg_PluginNotInitialized); if (ServiceManager.ServiceExists(eventName)) throw new ArgumentException("eventName"); EventHandle handle = new EventHandle(owner, eventName, MirandaContext.Current.PluginLink.NativePluginLink.CreateHookableEvent(eventName)); if (defaultSubscriber != null) handle.SetDefaultSubscriber(defaultSubscriber); return handle; }