public static void RegisterForUpdate(Update update) { if (update == null) throw new ArgumentNullException("update"); if (!IsUpdateSupported()) throw new NotSupportedException(); UnmanagedStructHandle<UPDATE> updateHandle = UnmanagedStructHandle<UPDATE>.Empty; try { UPDATE updateNative; update.MarshalToNative(out updateNative); updateHandle = new UnmanagedStructHandle<UPDATE>(ref updateNative); int result = MirandaContext.Current.CallService(MS_UPDATE_REGISTER, UIntPtr.Zero, updateHandle.IntPtr); if (result != 0) throw new MirandaException(String.Format(TextResources.ExceptionMsg_Formatable2_MirandaServiceReturnedFailure, MS_UPDATE_REGISTER, result.ToString())); } catch (MirandaException) { throw; } catch (Exception e) { throw new MirandaException(TextResources.ExceptionMsg_ErrorWhileCallingMirandaService, e); } finally { updateHandle.Free(); } }
internal void Register() { if (Registered) throw new InvalidOperationException(); PROTOCOLDESCRIPTOR descriptor = new PROTOCOLDESCRIPTOR(Name, Type); UnmanagedStructHandle<PROTOCOLDESCRIPTOR> nativeHandle = UnmanagedStructHandle<PROTOCOLDESCRIPTOR>.Empty; try { nativeHandle = new UnmanagedStructHandle<PROTOCOLDESCRIPTOR>(ref descriptor); int result = Context.CallService(MirandaServices.MS_PROTO_REGISTERMODULE, UIntPtr.Zero, nativeHandle.IntPtr); if (result != 0) throw new MirandaException(String.Format(TextResources.ExceptionMsg_Formatable2_MirandaServiceReturnedFailure, result.ToString())); this.nativeDescriptor = descriptor; Registered = true; } finally { nativeHandle.Free(); } }
public IntPtr AddEvent(ContactInfo associatedContact, object data, string owner, DatabaseEventType type, DatabaseEventProperties flags, DateTime? timestamp, bool throwOnFailure) { if (associatedContact == null) throw new ArgumentNullException("associatedContact"); if (String.IsNullOrEmpty(owner)) throw new ArgumentNullException("owner"); if (data == null) throw new ArgumentNullException("data"); IntPtr pBlob = IntPtr.Zero; UnmanagedStructHandle<DBEVENTINFO> nativeStruct = UnmanagedStructHandle<DBEVENTINFO>.Empty; try { int totalBytes; if (data is string) { totalBytes = DBEVENTINFO.LayoutAnsiUniString((string)data, out pBlob); } else if (data is byte[]) { byte[] dataBytes = (byte[])data; totalBytes = dataBytes.Length; pBlob = Marshal.AllocHGlobal(totalBytes); Marshal.Copy(dataBytes, 0, pBlob, dataBytes.Length); } else throw new ArgumentOutOfRangeException("data"); DBEVENTINFO info = new DBEVENTINFO(0, IntPtr.Zero); info.Module = Translate.ToHandle(owner, StringEncoding.Ansi).IntPtr; info.BlobSize = (uint)totalBytes; info.BlobPtr = pBlob; info.EventType = (ushort)type; info.Flags = (uint)flags; info.Timestamp = Utilities.GetTimestamp(timestamp.HasValue ? timestamp.Value : DateTime.Now); nativeStruct = new UnmanagedStructHandle<DBEVENTINFO>(ref info, pBlob, info.Module); IntPtr eventHandle = (IntPtr)MirandaContext.Current.CallService(MS_DB_EVENT_ADD, associatedContact.MirandaHandle, nativeStruct.IntPtr); if (eventHandle == IntPtr.Zero && throwOnFailure) throw new MirandaException(String.Format(TextResources.ExceptionMsg_Formatable2_MirandaServiceReturnedFailure, MS_DB_EVENT_ADD, eventHandle.ToString())); else return eventHandle; } finally { nativeStruct.Free(); } }
public IntPtr AddEvent(ContactInfo contact, Icon icon, string serviceToCall, IntPtr lParamToPass, IntPtr eventToken, ContactListEventProperties properties, string toolTip) { if (contact == null) throw new ArgumentNullException("contact"); if (icon == null) throw new ArgumentNullException("icon"); ContactListEvent clistEvent = new ContactListEvent(); clistEvent.ContactHandle = contact.MirandaHandle; clistEvent.EventHandle = eventToken; clistEvent.Flags = (uint)properties; clistEvent.IconHandle = icon.Handle; clistEvent.LParam = lParamToPass; clistEvent.ServiceName = serviceToCall; clistEvent.Tooltip = toolTip; UnmanagedStructHandle<ContactListEvent> nativeStruct = UnmanagedStructHandle<ContactListEvent>.Empty; try { nativeStruct = new UnmanagedStructHandle<ContactListEvent>(ref clistEvent); IntPtr eventHandle = (IntPtr)MirandaContext.Current.CallService(MS_CLIST_ADDEVENT, UIntPtr.Zero, nativeStruct.IntPtr); if (eventHandle != IntPtr.Zero) throw new MirandaException(String.Format(TextResources.ExceptionMsg_Formatable2_MirandaServiceReturnedFailure, MS_CLIST_ADDEVENT, eventHandle.ToString())); return clistEvent.EventHandle; } finally { nativeStruct.Free(); } }
public bool ShowBaloonTip(string title, string text, string protocol, ToolTipIcon icon, int timeout) { UnmanagedStructHandle<MIRANDASYSTRAYNOTIFY> nativeHandle = UnmanagedStructHandle<MIRANDASYSTRAYNOTIFY>.Empty; try { MIRANDASYSTRAYNOTIFY msn = new MIRANDASYSTRAYNOTIFY(title, text, icon); msn.Timeout = (uint)timeout; msn.Protocol = protocol; nativeHandle = new UnmanagedStructHandle<MIRANDASYSTRAYNOTIFY>(ref msn); int result = MirandaContext.Current.CallService(MirandaServices.MS_CLIST_SYSTRAY_NOTIFY, UIntPtr.Zero, nativeHandle.IntPtr); bool retValue = (result == 0); Debug.Assert(retValue); return retValue; } finally { nativeHandle.Free(); } }
public bool ModifyMenuItem(MirandaPlugin owner, MenuItemDeclarationAttribute menuItem, string text, MenuItemProperties flags, Icon icon, HotKeys hotKey, bool updateItemDescriptor) { if (owner == null) throw new ArgumentNullException("owner"); if (menuItem == null) throw new ArgumentNullException("menuItem"); if (menuItem.MirandaHandle == IntPtr.Zero) throw new ArgumentException("Invalid menu item handle."); UnmanagedStructHandle<CLISTMENUITEM> nativeHandle = UnmanagedStructHandle<CLISTMENUITEM>.Empty; try { SynchronizationHelper.BeginMenuItemUpdate(menuItem); CLISTMENUITEM nativeItem = new CLISTMENUITEM(owner, menuItem); MenuItemModifyFlags modifyFlags = MenuItemModifyFlags.None; if (text != null) { modifyFlags |= MenuItemModifyFlags.CMIM_NAME; nativeItem.Text = text; if (updateItemDescriptor) menuItem.Text = text; } if (flags != MenuItemProperties.KeepCurrent) { modifyFlags |= MenuItemModifyFlags.CMIM_FLAGS; nativeItem.Flags = (uint)flags; if (updateItemDescriptor) menuItem.Flags = flags; } if (icon != null) { modifyFlags |= MenuItemModifyFlags.CMIM_ICON; nativeItem.Icon = icon.Handle; } if (hotKey != 0) { modifyFlags |= MenuItemModifyFlags.CMIM_HOTKEY; nativeItem.HotKey = (uint)hotKey; if (updateItemDescriptor) menuItem.HotKey = hotKey; } nativeItem.Flags |= (uint)modifyFlags; nativeHandle = new UnmanagedStructHandle<CLISTMENUITEM>(ref nativeItem); bool result = MirandaContext.Current.CallService(MirandaServices.MS_CLIST_MODIFYMENUITEM, (UIntPtr)(uint)menuItem.MirandaHandle, nativeHandle.IntPtr) == 0 ? true : false; Debug.Assert(result); return result; } catch (Exception e) { throw new MirandaException(TextResources.ExceptionMsg_ErrorWhileCallingMirandaService + e.Message, e); } finally { nativeHandle.Free(); SynchronizationHelper.EndUpdate(menuItem); } }
public void AddMenuItem(MirandaPlugin owner, MenuItemDeclarationAttribute item) { if (owner == null) throw new ArgumentNullException("owner"); if (item == null) throw new ArgumentNullException("item"); string serviceName = item.IsContactMenuItem ? MirandaServices.MS_CLIST_ADDCONTACTMENUITEM : MirandaServices.MS_CLIST_ADDMAINMENUITEM; UnmanagedStructHandle<CLISTMENUITEM> nativeHandle = UnmanagedStructHandle<CLISTMENUITEM>.Empty; CLISTMENUITEM nativeItem = new CLISTMENUITEM(owner, item); try { nativeHandle = new UnmanagedStructHandle<CLISTMENUITEM>(ref nativeItem); IntPtr handle = (IntPtr)MirandaContext.Current.CallService(serviceName, UIntPtr.Zero, nativeHandle.IntPtr, (owner is StandalonePlugin && !item.IsAdditional)); item.MirandaHandle = handle; Debug.Assert(handle != IntPtr.Zero); } finally { nativeHandle.Free(); } }
private void GetMMInterface() { mirandaMemoryManager = new MM_INTERFACE(); mirandaMemoryManager.Size = Marshal.SizeOf(typeof(MM_INTERFACE)); UnmanagedStructHandle<MM_INTERFACE> mmiHandle = new UnmanagedStructHandle<MM_INTERFACE>(ref mirandaMemoryManager); try { if (CallService(MS_SYSTEM_GET_MMI, IntPtr.Zero, mmiHandle.IntPtr) == CallbackResult.Success) mmiHandle.MarshalBack(out mirandaMemoryManager); else throw new MirandaException(String.Format(TextResources.ExceptionMsg_Formatable2_MirandaServiceReturnedFailure, MS_SYSTEM_GET_MMI, "1")); } finally { mmiHandle.Free(); } }