mit hyphen

This commit is contained in:
2013-06-25 22:53:41 +00:00
parent 8896edc368
commit 318d93e6c1
424 changed files with 161843 additions and 2 deletions
+65
View File
@@ -0,0 +1,65 @@
/***********************************************************************\
* Virtuoso.Miranda.Plugins (Hyphen) *
* Provides a managed wrapper for API of IM client Miranda. *
* Copyright (C) 2006-2009 virtuoso *
* deml.tomas@seznam.cz *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
* License as published by the Free Software Foundation; either *
* version 2.1 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
\***********************************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace Virtuoso.Miranda.Plugins.Native
{
[StructLayout(LayoutKind.Sequential, Pack = 4)]
public struct ACKDATA
{
private readonly int Size;
public IntPtr ModuleName;
public IntPtr ContactHandle;
public int Type;
public int Result;
public IntPtr ProcessHandle;
public IntPtr LParam;
public ACKDATA(IntPtr moduleName, int type, int result)
{
this.ModuleName = moduleName;
this.Type = type;
this.Result = result;
this.ContactHandle = IntPtr.Zero;
this.ProcessHandle = IntPtr.Zero;
this.LParam = IntPtr.Zero;
this.Size = Marshal.SizeOf(typeof(ACKDATA));
}
}
//a general network 'ack'
//wParam=0
//lParam=(LPARAM)(ACKDATA*)&ack
//Note that just because definitions are here doesn't mean they will be sent.
//Read the documentation for the function you are calling to see what replies
//you will receive.
/*typedef struct {
int cbSize;
const char *szModule; //the name of the protocol module which initiated this ack
HANDLE hContact;
int type; //an ACKTYPE_ constant
int result; //an ACKRESULT_ constant
HANDLE hProcess; //a caller-defined process code
LPARAM lParam; //caller-defined extra info
} ACKDATA;*/
}
+41
View File
@@ -0,0 +1,41 @@
/***********************************************************************\
* Virtuoso.Miranda.Plugins (Hyphen) *
* Provides a managed wrapper for API of IM client Miranda. *
* Copyright (C) 2006-2009 virtuoso *
* deml.tomas@seznam.cz *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
* License as published by the Free Software Foundation; either *
* version 2.1 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
\***********************************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace Virtuoso.Miranda.Plugins.Native
{
[StructLayout( LayoutKind.Sequential, Pack = 4, CharSet = CharSet.Ansi)]
internal struct ADDCONTACTSTRUCT
{
public int HandleType;
public IntPtr Handle;
public string Protocol;
}
/*
* typedef struct{
int handleType; //one of the HANDLE_ constants
HANDLE handle; //hDbEvent if acs.handleType==HANDLE_EVENT, hContact if acs.handleType==HANDLE_CONTACT, ignored if acs.handleType==HANDLE_SEARCHRESULT
const char *szProto; //ignored if acs.handleType!=HANDLE_SEARCHRESULT
PROTOSEARCHRESULT *psr; //ignored if acs.handleType!=HANDLE_SEARCHRESULT
}ADDCONTACTSTRUCT;
*/
}
+58
View File
@@ -0,0 +1,58 @@
/***********************************************************************\
* Virtuoso.Miranda.Plugins (Hyphen) *
* Provides a managed wrapper for API of IM client Miranda. *
* Copyright (C) 2006-2009 virtuoso *
* deml.tomas@seznam.cz *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
* License as published by the Free Software Foundation; either *
* version 2.1 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
\***********************************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using Virtuoso.Miranda.Plugins.Infrastructure;
namespace Virtuoso.Miranda.Plugins.Native
{
[StructLayout(LayoutKind.Sequential, Pack = 4)]
internal struct CCSDATA
{
#region Fields
public readonly IntPtr ContactHandle;
public IntPtr ServiceNamePtr;
public UIntPtr WParam;
public IntPtr LParam;
#endregion
#region .ctors
public CCSDATA(ContactInfo contact, string serviceName)
{
this.ContactHandle = contact.MirandaHandle;
this.ServiceNamePtr = new UnmanagedStringHandle(serviceName, StringEncoding.Ansi).IntPtr;
this.WParam = UIntPtr.Zero;
this.LParam = IntPtr.Zero;
}
public void Free()
{
if (ServiceNamePtr != IntPtr.Zero)
Marshal.FreeHGlobal(ServiceNamePtr);
}
#endregion
}
}
+128
View File
@@ -0,0 +1,128 @@
/***********************************************************************\
* Virtuoso.Miranda.Plugins (Hyphen) *
* Provides a managed wrapper for API of IM client Miranda. *
* Copyright (C) 2006-2009 virtuoso *
* deml.tomas@seznam.cz *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
* License as published by the Free Software Foundation; either *
* version 2.1 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
\***********************************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.Reflection;
using Virtuoso.Miranda.Plugins.Infrastructure;
using System.Drawing;
using System.Diagnostics;
using System.IO;
namespace Virtuoso.Miranda.Plugins.Native
{
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 4)]
internal struct CLISTMENUITEM
{
#region Fields
private readonly int Size;
public string Text;
public uint Flags;
public int Position;
public IntPtr Icon;
public string Service;
public string PopUpMenu;
public int PopUpPosition;
public uint HotKey;
public string ContactOwner;
#endregion
#region .ctors
public CLISTMENUITEM(MirandaPlugin owner, MenuItemDeclarationAttribute attrib)
{
if (owner == null)
throw new ArgumentNullException("owner");
if (attrib == null)
throw new ArgumentNullException("attrib");
this.Text = attrib.Text;
this.Service = attrib.Service;
this.ContactOwner = attrib.OwningModule;
this.Flags = (uint)attrib.Flags;
this.PopUpMenu = attrib.PopUpMenu;
this.PopUpPosition = attrib.PopUpPosition;
this.Position = attrib.Position;
this.HotKey = (uint)attrib.HotKey;
this.Icon = IntPtr.Zero;
this.Size = Marshal.SizeOf(typeof(CLISTMENUITEM));
LoadIcon(owner, attrib);
}
#endregion
#region Methods
private void LoadIcon(MirandaPlugin owner, MenuItemDeclarationAttribute attrib)
{
try
{
if (!attrib.HasIcon)
return;
if (attrib.UseEmbeddedIcon)
{
using (Stream stream = owner.GetType().Assembly.GetManifestResourceStream(attrib.IconID))
{
if (stream != null)
Icon = IconImageCache.Singleton.GetStreamedIcon(stream).Handle;
else
Debug.Fail("Embedded icon not found.");
}
}
else
Icon = Skin.LoadIcon(int.Parse(attrib.IconID));
}
catch
{
this.Icon = IntPtr.Zero;
}
}
#endregion
}
/*
typedef struct {
int cbSize; //size in bytes of this structure
char *pszName; //text of the menu item
DWORD flags; //flags
int position; //approx position on the menu. lower numbers go nearer the top
HICON hIcon; //HasIcon to put by the item. If this was not loaded from
//a resource, you can delete it straight after the call
char *pszService; //eventName of service to call when the item gets selected
char *pszPopupName; //eventName of the popup menu that this item is on. If this
//is NULL the item is on the root of the menu
int popupPosition; //position of the popup menu on the root menu. Ignored
//if pszPopupName is NULL or the popup menu already
//existed
DWORD hotKey; //keyboard accelerator, same as lParam of WM_HOTKEY
//0 for none
char *pszContactOwner; //contact menus only. The protocol module that owns
//the contacts to which this menu item applies. NULL if it
//applies to all contacts. If it applies to multiple but not all
//protocols, add multiple menu items or use ME_CLIST_PREBUILDCONTACTMENU
} CLISTMENUITEM;
*/
}
+71
View File
@@ -0,0 +1,71 @@
/***********************************************************************\
* Virtuoso.Miranda.Plugins (Hyphen) *
* Provides a managed wrapper for API of IM client Miranda. *
* Copyright (C) 2006-2009 virtuoso *
* deml.tomas@seznam.cz *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
* License as published by the Free Software Foundation; either *
* version 2.1 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
\***********************************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using Virtuoso.Miranda.Plugins.Infrastructure;
namespace Virtuoso.Miranda.Plugins.Native
{
[StructLayout(LayoutKind.Sequential, Pack = 4)]
internal struct CONTACTINFO
{
#region Fields
private readonly int Size;
public byte Flag;
public IntPtr ContactHandle;
public IntPtr Module;
public byte Type;
public IntPtr Value;
#endregion
#region .ctors
public CONTACTINFO(IntPtr contactHandle, IntPtr module)
{
this.ContactHandle = contactHandle;
this.Flag = 0;
this.Module = module;
this.Type = 0;
this.Value = IntPtr.Zero;
this.Size = Marshal.SizeOf(typeof(CONTACTINFO));
}
#endregion
}
/*typedef struct {
int cbSize;
BYTE dwFlag;
HANDLE hContact;
char *szProto;
BYTE type;
union {
BYTE bVal;
WORD wVal;
DWORD dVal;
char *pszVal;
WORD cchVal;
};
} CONTACTINFO;*/
}
+102
View File
@@ -0,0 +1,102 @@
/***********************************************************************\
* Virtuoso.Miranda.Plugins (Hyphen) *
* Provides a managed wrapper for API of IM client Miranda. *
* Copyright (C) 2006-2009 virtuoso *
* deml.tomas@seznam.cz *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
* License as published by the Free Software Foundation; either *
* version 2.1 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
\***********************************************************************/
using System;
using System.Runtime.InteropServices;
using Virtuoso.Miranda.Plugins.Infrastructure;
namespace Virtuoso.Miranda.Plugins.Native
{
[StructLayout(LayoutKind.Sequential, Pack = 4, CharSet = CharSet.Ansi)]
internal struct DBCONTACTWRITESETTING
{
#region Fields
public IntPtr Module;
public IntPtr Name;
public DBVARIANT Value;
#endregion
#region Methods
public static unsafe object ExtractValue(IntPtr pDbWriteSetting)
{
DBCONTACTWRITESETTING dbWriteSetting = *(DBCONTACTWRITESETTING*)pDbWriteSetting.ToPointer();
switch ((DatabaseSettingType)dbWriteSetting.Value.Type)
{
case DatabaseSettingType.AsciiString:
return Marshal.PtrToStringAnsi(dbWriteSetting.Value.Text.TextPtr);
case DatabaseSettingType.UnicodeString:
case DatabaseSettingType.UTF8String:
return Marshal.PtrToStringUni(dbWriteSetting.Value.Text.TextPtr);
case DatabaseSettingType.Byte:
return dbWriteSetting.Value.Primitives.Byte;
case DatabaseSettingType.UInt16:
return dbWriteSetting.Value.Primitives.Word;
case DatabaseSettingType.UInt32:
return dbWriteSetting.Value.Primitives.DWord;
case DatabaseSettingType.Blob:
return Translate.ToBlob(dbWriteSetting.Value.Blob.BlobPtr, dbWriteSetting.Value.Blob.Size);
case DatabaseSettingType.Deleted:
return null;
default:
LogUnsupportedValue(dbWriteSetting);
return null;
}
}
private static void LogUnsupportedValue(DBCONTACTWRITESETTING dbWriteSetting)
{
string name = "N/A";
string module = "N/A";
try
{
name = Translate.ToString(dbWriteSetting.Name, StringEncoding.Ansi);
module = Translate.ToString(dbWriteSetting.Module, StringEncoding.Ansi);
}
catch (Exception)
{ }
Log.Warning("Attempted to extract an unsupported DB contact setting {0}:{1} of type {1}",
module, name, dbWriteSetting.Value.Type.ToString("X"));
}
#endregion
}
[StructLayout(LayoutKind.Sequential, Pack = 4, CharSet = CharSet.Ansi)]
internal struct DBCONTACTGETSETTING
{
public string Module;
public string Name;
public IntPtr DbVariantPtr;
}
/*[StructLayout(LayoutKind.Sequential, Pack = 4, CharSet = CharSet.Ansi)]
internal struct DBCONTACTGETSETTING_PTR
{
public IntPtr Module;
public IntPtr Name;
public IntPtr DbVariant;
}*/
}
+40
View File
@@ -0,0 +1,40 @@
/***********************************************************************\
* Virtuoso.Miranda.Plugins (Hyphen) *
* Provides a managed wrapper for API of IM client Miranda. *
* Copyright (C) 2006-2009 virtuoso *
* deml.tomas@seznam.cz *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
* License as published by the Free Software Foundation; either *
* version 2.1 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
\***********************************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace Virtuoso.Miranda.Plugins.Native
{
[StructLayout(LayoutKind.Sequential, Pack = 4)]
internal struct DBEVENTGETTEXT
{
public IntPtr DbEventInfoPtr;
public int DataType;
public int Codepage;
}
/* m_database.h
* typedef struct {
* DBEVENTINFO* dbei;
* int datatype;
* int codepage;
* } DBEVENTGETTEXT;
*/
}
+140
View File
@@ -0,0 +1,140 @@
/***********************************************************************\
* Virtuoso.Miranda.Plugins (Hyphen) *
* Provides a managed wrapper for API of IM client Miranda. *
* Copyright (C) 2006-2009 virtuoso *
* deml.tomas@seznam.cz *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
* License as published by the Free Software Foundation; either *
* version 2.1 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
\***********************************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace Virtuoso.Miranda.Plugins.Native
{
[StructLayout(LayoutKind.Sequential, Pack = 4), CLSCompliant(false), Serializable]
public struct DBEVENTINFO
{
#region Fields
private readonly int Size;
public IntPtr Module;
public UInt32 Timestamp;
public UInt32 Flags;
public UInt16 EventType;
public UInt32 BlobSize;
[NonSerialized]
public IntPtr BlobPtr;
#endregion
#region .ctors
public DBEVENTINFO(int blobSize, IntPtr blobPtr)
{
this.Module = IntPtr.Zero;
this.Timestamp = this.Flags = this.EventType = 0;
this.BlobSize = (uint)blobSize;
this.BlobPtr = blobPtr;
unsafe
{
this.Size = sizeof(DBEVENTINFO);
}
}
#endregion
#region Methods
/// <summary>
/// Formats the ANSI-\0-UNICODE-\0\0 layout in the memory.
/// </summary>
/// <param name="data">String to layout.</param>
/// <param name="pBlob">[OUT] Blob pointer to the resulting memory layout.</param>
/// <returns>Blob size in bytes.</returns>
/// <remarks>Message blob format: ansi\0unicode\0\0</remarks>
public static int LayoutAnsiUniString(string data, out IntPtr pBlob)
{
int ansiBytesCount = Encoding.Default.GetByteCount(data);
int unicodeBytesCount = Encoding.Unicode.GetByteCount(data);
int terminatorBytesCount = 3;
int totalBytes = ansiBytesCount + unicodeBytesCount + terminatorBytesCount;
pBlob = Marshal.AllocHGlobal(totalBytes);
IntPtr pAnsiEnd = new IntPtr(pBlob.ToInt64() + (long)ansiBytesCount);
IntPtr pAnsiTermEnd = new IntPtr(pAnsiEnd.ToInt64() + 1L);
Marshal.Copy(Encoding.Default.GetBytes(data), 0, pBlob, ansiBytesCount);
Marshal.Copy(new char[] { '\0' }, 0, pAnsiEnd, 1);
Marshal.Copy(Encoding.Unicode.GetBytes(data), 0, pAnsiTermEnd, unicodeBytesCount);
Marshal.Copy(new char[] { '\0', '\0' }, 0, new IntPtr(pAnsiTermEnd.ToInt64() + (long)unicodeBytesCount), 2);
return totalBytes;
}
#endregion
}
[StructLayout(LayoutKind.Sequential)]
internal struct DBTIMETOSTRING
{
#region Fields
public IntPtr Format;
public IntPtr Output;
public int MaxBytes;
#endregion
#region .ctors
public DBTIMETOSTRING(string format)
{
Format = new UnmanagedStringHandle(format, StringEncoding.Ansi).IntPtr;
Output = IntPtr.Zero;
MaxBytes = 0;
}
public void Free()
{
if (Format != IntPtr.Zero)
Marshal.FreeHGlobal(Format);
}
#endregion
}
// typedef struct {
// char *szFormat; //format string, as above
// char *szDest; //place to put the output string
// int cbDest; //maximum number of bytes to put in szDest
//} DBTIMETOSTRING;
// typedef struct {
// int cbSize; //size of the structure in bytes
// char *szModule; //pointer to eventName of the module that 'owns' this
// //event, ie the one that is in control of the data format
// DWORD timestamp; //seconds since 00:00, 01/01/1970. Gives us times until
// //2106 unless you use the standard C library which is
// //signed and can only do until 2038. In GMT.
// DWORD flags; //the omnipresent flags
// WORD eventType; //module-defined event type field
// DWORD cbBlob; //size of pBlob in bytes
// PBYTE pBlob; //pointer to buffer containing module-defined event data
//} DBEVENTINFO;
}
+116
View File
@@ -0,0 +1,116 @@
/***********************************************************************\
* Virtuoso.Miranda.Plugins (Hyphen) *
* Provides a managed wrapper for API of IM client Miranda. *
* Copyright (C) 2006-2009 virtuoso *
* deml.tomas@seznam.cz *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
* License as published by the Free Software Foundation; either *
* version 2.1 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
\***********************************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace Virtuoso.Miranda.Plugins.Native
{
internal enum DbVariantValue : byte
{
DBVT_DELETED = 0, //this setting just got deleted, no other values are valid
DBVT_BYTE = 1, //bVal and cVal are valid
DBVT_WORD = 2, //wVal and sVal are valid
DBVT_DWORD = 4, //dVal and lVal are valid
DBVT_ASCIIZ = 255, //pszVal is valid
DBVT_BLOB = 254, //cpbVal and pbVal are valid
DBVT_UTF8 = 253, //pszVal is valid
DBVT_WCHAR = 252, //pszVal is valid
DBVTF_VARIABLELENGTH = 0x80
}
[StructLayout(LayoutKind.Explicit, Pack = 4, Size = 12)]
internal struct DBVARIANT
{
[FieldOffset(0)]
public byte Type;
[FieldOffset(4)]
public DBVARIANT_PRIMITIVE Primitives;
[FieldOffset(4)]
public DBVARIANT_TEXT Text;
[FieldOffset(4)]
public DBVARIANT_BLOB Blob;
}
[StructLayout(LayoutKind.Explicit, Pack = 4)]
internal struct DBVARIANT_PRIMITIVE
{
[FieldOffset(0)]
public byte Byte;
[FieldOffset(0)]
public char Char;
[FieldOffset(0)]
public UInt16 Word;
[FieldOffset(0)]
public short Short;
[FieldOffset(0)]
public UInt32 DWord;
[FieldOffset(0)]
public int Integer;
}
[StructLayout(LayoutKind.Explicit, Pack = 4)]
internal struct DBVARIANT_TEXT
{
[FieldOffset(0)]
public IntPtr TextPtr;
[FieldOffset(4)]
public UInt16 TextBufferSize;
}
[StructLayout(LayoutKind.Explicit, Pack = 4)]
internal struct DBVARIANT_BLOB
{
[FieldOffset(0)]
public UInt16 Size;
[FieldOffset(2)]
public IntPtr BlobPtr;
}
// typedef struct {
// BYTE type;
// union {
// BYTE bVal; char cVal;
// WORD wVal; short sVal;
// DWORD dVal; long lVal;
// struct {
// union {
// char *pszVal;
// TCHAR *ptszVal;
// WCHAR *pwszVal;
// };
// WORD cchVal; //only used for db/contact/getsettingstatic
// };
// struct {
// WORD cpbVal;
// BYTE *pbVal;
// };
// };
//} DBVARIANT;
}
@@ -0,0 +1,29 @@
/***********************************************************************\
* Virtuoso.Miranda.Plugins (Hyphen) *
* Provides a managed wrapper for API of IM client Miranda. *
* Copyright (C) 2006-2009 virtuoso *
* deml.tomas@seznam.cz *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
* License as published by the Free Software Foundation; either *
* version 2.1 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
\***********************************************************************/
using System;
using System.Collections.Generic;
using System.Text;
namespace Virtuoso.Miranda.Plugins.Native
{
public interface IUnmanagedMemoryHandle : IDisposable
{
IntPtr IntPtr { get; }
void Free();
}
}
+193
View File
@@ -0,0 +1,193 @@
/***********************************************************************\
* Virtuoso.Miranda.Plugins (Hyphen) *
* Provides a managed wrapper for API of IM client Miranda. *
* Copyright (C) 2006-2009 virtuoso *
* deml.tomas@seznam.cz *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
* License as published by the Free Software Foundation; either *
* version 2.1 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
\***********************************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.IO;
using System.Runtime.CompilerServices;
namespace Virtuoso.Miranda.Plugins.Native
{
internal sealed class IconImageCache
{
#region Fields
private static IconImageCache singleton;
private readonly Dictionary<IntPtr, Icon> IconCache;
private readonly Dictionary<int, Icon> StreamedIconCache;
private readonly Dictionary<Icon, Image> ImageCache;
#endregion
#region .ctors
[MethodImpl(MethodImplOptions.Synchronized)]
private IconImageCache()
{
IconCache = new Dictionary<IntPtr, Icon>(1);
StreamedIconCache = new Dictionary<int, Icon>(1);
ImageCache = new Dictionary<Icon, Image>(1);
}
#endregion
#region Properties
public static IconImageCache Singleton
{
get
{
return singleton ?? (singleton = new IconImageCache());
}
}
#endregion
#region GetXY methods
public Icon GetIcon(IntPtr handle)
{
lock (IconCache)
{
Icon icon = null;
IntPtr key = handle;
if (IconCache.ContainsKey(key))
icon = IconCache[key];
else
IconCache[key] = icon = Icon.FromHandle(handle);
return icon;
}
}
public Icon GetStreamedIcon(Stream stream)
{
lock (StreamedIconCache)
{
lock (IconCache)
{
int streamHandle = ComputeStreamHandle(stream);
if (StreamedIconCache.ContainsKey(streamHandle))
return StreamedIconCache[streamHandle];
Icon icon = new Icon(stream);
StreamedIconCache[streamHandle] = icon;
if (!IconCache.ContainsKey(icon.Handle))
IconCache[icon.Handle] = icon;
return icon;
}
}
}
private static int ComputeStreamHandle(Stream stream)
{
lock (stream)
{
int streamHandle = 0, result;
long prevPosition = stream.Position;
stream.Position = 0;
while ((result = stream.ReadByte()) != -1)
streamHandle += (byte)result;
stream.Position = prevPosition;
return streamHandle;
}
}
public Image GetIconImage(IntPtr handle)
{
Image image = null;
Icon icon = GetIcon(handle);
lock (ImageCache)
{
if (ImageCache.ContainsKey(icon))
image = ImageCache[icon];
else
ImageCache[icon] = image = icon.ToBitmap();
return image;
}
}
public bool IsCached(IntPtr handle)
{
lock (IconCache)
return IconCache.ContainsKey(handle);
}
public bool IsCached(Stream stream)
{
lock (StreamedIconCache)
return StreamedIconCache.ContainsKey(ComputeStreamHandle(stream));
}
#endregion
#region IDisposable Members
public void Dispose()
{
Dispose(true);
}
[MethodImpl(MethodImplOptions.Synchronized)]
private void Dispose(bool disposing)
{
GC.SuppressFinalize(this);
if (disposing)
{
lock (IconCache)
{
lock (ImageCache)
{
lock (StreamedIconCache)
{
foreach (Icon icon in IconCache.Values)
icon.Dispose();
foreach (Icon icon in StreamedIconCache.Values)
icon.Dispose();
foreach (Image image in ImageCache.Values)
image.Dispose();
IconCache.Clear();
StreamedIconCache.Clear();
ImageCache.Clear();
singleton = null;
}
}
}
}
}
#endregion
}
}
+246
View File
@@ -0,0 +1,246 @@
/***********************************************************************\
* Virtuoso.Miranda.Plugins (Hyphen) *
* Provides a managed wrapper for API of IM client Miranda. *
* Copyright (C) 2006-2009 virtuoso *
* deml.tomas@seznam.cz *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
* License as published by the Free Software Foundation; either *
* version 2.1 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
\***********************************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.Threading;
using System.Runtime.CompilerServices;
using System.Diagnostics;
using Virtuoso.Hyphen;
using Virtuoso.Miranda.Plugins.Resources;
namespace Virtuoso.Miranda.Plugins.Native
{
// Every method touching a memory location or returning its address requires the buffer to be suspended!
[CLSCompliant(false)]
public sealed class InteropBuffer : IUnmanagedMemoryHandle
{
#region Fields
private const string LogCategory = Loader.LogCategory + "::InteropBuffer";
private readonly int size;
private IntPtr sizeAsIntPtr;
private UIntPtr sizeAsUIntPtr;
private readonly object SyncObject;
private IntPtr intPtr;
private volatile int Owner;
private volatile bool reserved;
#endregion
#region .ctors
internal InteropBuffer(int size)
{
if (size <= 0) throw new ArgumentOutOfRangeException("size");
SyncObject = new object();
Log.DebuggerWrite(0, LogCategory, "InteropBuffer SyncObject initialized");
this.size = size;
intPtr = Marshal.AllocHGlobal(size);
Log.DebuggerWrite(0, LogCategory, "InteropBuffer memory allocated (" + size + " B)");
}
~InteropBuffer()
{
Dispose(false);
}
private void CheckLock()
{
if (Owner == 0) throw new InvalidOperationException(TextResources.ExceptionMsg_InteropBufferNotLocked);
}
#endregion
#region IUnmanagedMemoryHandle Members
public IntPtr IntPtr
{
get
{
lock (SyncObject)
{
// Touches memory, lock needed
CheckLock();
if (intPtr == IntPtr.Zero)
throw new ObjectDisposedException("InteropBuffer");
return intPtr;
}
}
}
void IUnmanagedMemoryHandle.Free()
{
lock (SyncObject)
{
CheckLock();
Dispose(true);
}
}
#endregion
#region IDisposable Members
void IDisposable.Dispose()
{
((IUnmanagedMemoryHandle)this).Free();
}
internal void Dispose(bool disposing)
{
GC.SuppressFinalize(this);
if (intPtr != IntPtr.Zero)
{
Marshal.FreeHGlobal(intPtr);
intPtr = IntPtr.Zero;
Log.DebuggerWrite(0, LogCategory, "InteropBuffer memory released");
}
}
#endregion
#region Properties
public bool Locked
{
get
{
return Owner != 0;
}
}
public int Size
{
get
{
return size;
}
}
public IntPtr SizeAsIntPtr
{
get
{
if (sizeAsIntPtr == IntPtr.Zero)
sizeAsIntPtr = new IntPtr(size);
return sizeAsIntPtr;
}
}
public UIntPtr SizeAsUIntPtr
{
get
{
if (sizeAsUIntPtr == UIntPtr.Zero)
sizeAsUIntPtr = (UIntPtr)(ulong)size;
return sizeAsUIntPtr;
}
}
internal bool Reserved
{
get
{
return reserved;
}
set
{
reserved = value;
}
}
#endregion
#region Methods
public override int GetHashCode()
{
return intPtr.GetHashCode();
}
public override bool Equals(object obj)
{
if (obj == null) return false;
InteropBuffer other = obj as InteropBuffer;
if (other == null) return false;
return (GetHashCode() == other.GetHashCode());
}
public void Lock()
{
Log.DebuggerWrite(0, LogCategory, "Attempting to lock InteropBuffer for thread id " + Thread.CurrentThread.ManagedThreadId);
Monitor.Enter(SyncObject);
Owner = Thread.CurrentThread.ManagedThreadId;
Log.DebuggerWrite(0, LogCategory, "InteropBuffer locked for thread id " + Owner);
}
public void Unlock()
{
Log.DebuggerWrite(0, LogCategory, "Attempting to unlock InteropBuffer of thread id " + Thread.CurrentThread.ManagedThreadId);
CheckLock();
if (Owner == Thread.CurrentThread.ManagedThreadId)
{
Monitor.Exit(SyncObject);
Log.DebuggerWrite(0, LogCategory, "InteropBuffer unlocked by thread id " + this.Owner);
Owner = 0;
}
else
throw new InvalidOperationException(TextResources.ExceptionMsg_InvalidCrossThreadInteropBufferUnlock);
}
public void Zero()
{
lock (SyncObject)
{
// Touches memory, lock needed
CheckLock();
for (int i = 0; i < Size; i++)
Marshal.WriteByte(intPtr, i, 0);
}
}
public static implicit operator IntPtr(InteropBuffer buffer)
{
return buffer.intPtr;
}
#endregion
}
}
+186
View File
@@ -0,0 +1,186 @@
/***********************************************************************\
* Virtuoso.Miranda.Plugins (Hyphen) *
* Provides a managed wrapper for API of IM client Miranda. *
* Copyright (C) 2006-2009 virtuoso *
* deml.tomas@seznam.cz *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
* License as published by the Free Software Foundation; either *
* version 2.1 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
\***********************************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.CompilerServices;
using Virtuoso.Miranda.Plugins.Resources;
namespace Virtuoso.Miranda.Plugins.Native
{
// Impl note: should be static, but UnitTests' private accessors dislike that...
[CLSCompliant(false)]
public sealed class InteropBufferPool
{
#region Fields
public const int DefaultMaximumAvailableBufferSize = 260;
private const int DefaultBuffersCount = 2;
private static int maximumAvailableBufferSize = DefaultMaximumAvailableBufferSize;
public static int MaximumAvailableBufferSize
{
get { return InteropBufferPool.maximumAvailableBufferSize; }
}
private static int NextAvailableBufferIndex;
private static InteropBuffer[] Buffers;
private static volatile bool Disposed;
#endregion
#region .ctors & .dctors
private InteropBufferPool() { }
#endregion
#region Methods
internal static void Dispose()
{
if (Disposed || Buffers == null)
return;
lock (Buffers)
{
Disposed = true;
for (int i = 0; i < Buffers.Length; i++)
{
try
{
Buffers[i].Dispose(true);
Buffers[i] = null;
}
catch { }
}
}
}
internal static void Refresh()
{
Dispose();
Buffers = null;
Disposed = false;
VerifyPoolConsistency();
}
private static void VerifyPoolConsistency()
{
if (Disposed)
throw new ObjectDisposedException("InteropBufferPool");
if (Buffers == null)
{
NextAvailableBufferIndex = 0;
maximumAvailableBufferSize = DefaultMaximumAvailableBufferSize;
Buffers = new InteropBuffer[DefaultBuffersCount];
for (int i = 0; i < DefaultBuffersCount; i++)
Buffers[i] = new InteropBuffer(maximumAvailableBufferSize);
}
}
public static InteropBuffer AcquireBuffer()
{
return AcquireBuffer(maximumAvailableBufferSize);
}
public static InteropBuffer AcquireBuffer(int size)
{
if (size <= 0)
throw new ArgumentOutOfRangeException("size");
VerifyPoolConsistency();
lock (Buffers)
{
InteropBuffer buffer = null;
if (NextAvailableBufferIndex > Buffers.Length - 1 || size > maximumAvailableBufferSize)
buffer = new InteropBuffer(size);
else
{
int index = Array.FindIndex<InteropBuffer>(Buffers, delegate(InteropBuffer _buffer)
{
if (_buffer.Size >= size)
return true;
else
return false;
});
if (index == -1 || index < NextAvailableBufferIndex)
buffer = new InteropBuffer(size);
else
{
buffer = Buffers[index];
NextAvailableBufferIndex++;
}
}
buffer.Reserved = true;
return buffer;
}
}
public static void ReleaseBuffer(InteropBuffer buffer)
{
if (buffer == null)
return;
if (buffer.Locked)
throw new InvalidOperationException(TextResources.ExceptionMsg_InteropBufferNotUnlocked);
if (!buffer.Reserved)
throw new ArgumentException();
VerifyPoolConsistency();
lock (Buffers)
{
if (Array.IndexOf(Buffers, buffer) == -1)
{
if (buffer.Size > maximumAvailableBufferSize)
{
if (NextAvailableBufferIndex <= Buffers.Length - 1)
{
Buffers[NextAvailableBufferIndex].Dispose(true);
Buffers[NextAvailableBufferIndex] = buffer;
maximumAvailableBufferSize = buffer.Size;
}
}
else
buffer.Dispose(true);
}
else
NextAvailableBufferIndex--;
buffer.Reserved = false;
}
}
#endregion
}
}
@@ -0,0 +1,65 @@
/***********************************************************************\
* Virtuoso.Miranda.Plugins (Hyphen) *
* Provides a managed wrapper for API of IM client Miranda. *
* Copyright (C) 2006-2009 virtuoso *
* deml.tomas@seznam.cz *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
* License as published by the Free Software Foundation; either *
* version 2.1 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
\***********************************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using Virtuoso.Miranda.Plugins.Infrastructure;
namespace Virtuoso.Miranda.Plugins.Native
{
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 4)]
internal struct MIRANDASYSTRAYNOTIFY
{
#region Fields
private readonly int Size;
public string Protocol;
public string Title;
public string Text;
public uint Flags;
public uint Timeout;
#endregion
#region .ctors
public MIRANDASYSTRAYNOTIFY(string title, string text, System.Windows.Forms.ToolTipIcon flags)
{
this.Protocol = String.Empty;
this.Title = title;
this.Text = text;
this.Flags = (uint)flags;
this.Timeout = 10 * 1000;
this.Size = Marshal.SizeOf(typeof(MIRANDASYSTRAYNOTIFY));
}
#endregion
}
/*typedef struct {
int cbSize; // sizeof(MIRANDASYSTRAY)
char *szProto; // protocol to show under (may have no effect)
char *szInfoTitle; // only 64chars of it will be used
char *szInfo; // only 256chars of it will be used
DWORD dwInfoFlags; // see NIIF_* stuff
UINT uTimeout; // how long to show the tip for
} MIRANDASYSTRAYNOTIFY;*/
}
+52
View File
@@ -0,0 +1,52 @@
/***********************************************************************\
* Virtuoso.Miranda.Plugins (Hyphen) *
* Provides a managed wrapper for API of IM client Miranda. *
* Copyright (C) 2006-2009 virtuoso *
* deml.tomas@seznam.cz *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
* License as published by the Free Software Foundation; either *
* version 2.1 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
\***********************************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace Virtuoso.Miranda.Plugins.Native
{
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate IntPtr MMI_MallocPrototype(int size);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate IntPtr MMI_ReallocPrototype(IntPtr ptr, int size);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate IntPtr MMI_FreePrototype(IntPtr ptr);
[StructLayout(LayoutKind.Sequential, Pack = 4)]
internal struct MM_INTERFACE
{
public int Size;
public readonly MMI_MallocPrototype Malloc;
public readonly MMI_ReallocPrototype Realloc;
public readonly MMI_FreePrototype Free;
}
/* m_system.h
* struct MM_INTERFACE
{
int cbSize;
void* (*mmi_malloc) (size_t);
void* (*mmi_realloc) (void*, size_t);
void (*mmi_free) (void*);
}
*/
}
@@ -0,0 +1,34 @@
/***********************************************************************\
* Virtuoso.Miranda.Plugins (Hyphen) *
* Provides a managed wrapper for API of IM client Miranda. *
* Copyright (C) 2006-2009 virtuoso *
* deml.tomas@seznam.cz *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
* License as published by the Free Software Foundation; either *
* version 2.1 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
\***********************************************************************/
using System;
using System.Collections.Generic;
using System.Text;
namespace Virtuoso.Miranda.Plugins.Native
{
[Flags]
internal enum MenuItemModifyFlags : uint
{
None = 0x0,
CMIM_NAME = 0x80000000,
CMIM_FLAGS = 0x40000000,
CMIM_ICON = 0x20000000,
CMIM_HOTKEY = 0x10000000,
CMIM_ALL = 0xF0000000
}
}
+37
View File
@@ -0,0 +1,37 @@
/***********************************************************************\
* Virtuoso.Miranda.Plugins (Hyphen) *
* Provides a managed wrapper for API of IM client Miranda. *
* Copyright (C) 2006-2009 virtuoso *
* deml.tomas@seznam.cz *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
* License as published by the Free Software Foundation; either *
* version 2.1 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
\***********************************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.Serialization;
namespace Virtuoso.Miranda.Plugins.Native
{
[Serializable]
public class MirandaException : Exception
{
#region .ctors
internal MirandaException(string message) : base(message) { }
internal MirandaException(string message, Exception inner) : base(message, inner) { }
protected MirandaException(SerializationInfo info, StreamingContext context) : base(info, context) { }
#endregion
}
}
+32
View File
@@ -0,0 +1,32 @@
/***********************************************************************\
* Virtuoso.Miranda.Plugins (Hyphen) *
* Provides a managed wrapper for API of IM client Miranda. *
* Copyright (C) 2006-2009 virtuoso *
* deml.tomas@seznam.cz *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
* License as published by the Free Software Foundation; either *
* version 2.1 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
\***********************************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.Drawing;
namespace Virtuoso.Miranda.Plugins.Native
{
/*internal static class NativeMethods
{
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetCursorPos(ref Point lpPoint);
}*/
}
@@ -0,0 +1,50 @@
/***********************************************************************\
* Virtuoso.Miranda.Plugins (Hyphen) *
* Provides a managed wrapper for API of IM client Miranda. *
* Copyright (C) 2006-2009 virtuoso *
* deml.tomas@seznam.cz *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
* License as published by the Free Software Foundation; either *
* version 2.1 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
\***********************************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using Virtuoso.Miranda.Plugins.Infrastructure;
namespace Virtuoso.Miranda.Plugins.Native
{
[StructLayout(LayoutKind.Sequential, Pack = 4)]
public struct PROTOCOLDESCRIPTOR
{
#region Fields
private readonly int Size;
public readonly IntPtr Name;
public readonly ProtocolType Type;
#endregion
#region .ctors
public PROTOCOLDESCRIPTOR(string name, ProtocolType type)
{
this.Name = Translate.ToHandle(name, StringEncoding.Ansi);
this.Type = type;
this.Size = Marshal.SizeOf(typeof(PROTOCOLDESCRIPTOR));
}
#endregion
}
}
+87
View File
@@ -0,0 +1,87 @@
/***********************************************************************\
* Virtuoso.Miranda.Plugins (Hyphen) *
* Provides a managed wrapper for API of IM client Miranda. *
* Copyright (C) 2006-2009 virtuoso *
* deml.tomas@seznam.cz *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
* License as published by the Free Software Foundation; either *
* version 2.1 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
\***********************************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace Virtuoso.Miranda.Plugins.Native
{
internal static class UUID
{
#region Hyphen
#region UUID
private static readonly Guid hyphenUUID = new Guid("A9CB92EC-A8C9-493a-8763-77EB1DBA8228");
public static Guid HyphenUUID
{
get { return UUID.hyphenUUID; }
}
#endregion
#region Interfaces
private static readonly Guid HyphenInterfaceUUID = new Guid("9E54961E-D2A2-4939-A23E-FF07F0A27D79");
private static IntPtr hyphenInterfaceUUIDs;
public static IntPtr HyphenInterfaceUUIDs
{
get
{
if (hyphenInterfaceUUIDs == IntPtr.Zero)
{
int uuidSize = Marshal.SizeOf(typeof(Guid));
hyphenInterfaceUUIDs = Marshal.AllocHGlobal(2 * uuidSize);
byte[] uuidBytes = HyphenInterfaceUUID.ToByteArray();
Marshal.Copy(uuidBytes, 0, hyphenInterfaceUUIDs, uuidBytes.Length);
// MIID_LAST
uuidBytes = Last.ToByteArray();
Marshal.Copy(uuidBytes, 0, new IntPtr(hyphenInterfaceUUIDs.ToInt64() + uuidSize), uuidBytes.Length);
}
return hyphenInterfaceUUIDs;
}
}
#endregion
#endregion
#region Miranda
public static Guid Last
{
get
{
return Guid.Empty;
}
}
private static Guid protocolUUID = new Guid(0x2a3c815e, 0xa7d9, 0x424b, 0xba, 0x30, 0x2, 0xd0, 0x83, 0x22, 0x90, 0x85);
public static Guid ProtocolUUID
{
get { return protocolUUID; }
}
#endregion
}
}
@@ -0,0 +1,152 @@
/***********************************************************************\
* Virtuoso.Miranda.Plugins (Hyphen) *
* Provides a managed wrapper for API of IM client Miranda. *
* Copyright (C) 2006-2009 virtuoso *
* deml.tomas@seznam.cz *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
* License as published by the Free Software Foundation; either *
* version 2.1 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
\***********************************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using Virtuoso.Miranda.Plugins.Infrastructure;
using Virtuoso.Miranda.Plugins.Resources;
namespace Virtuoso.Miranda.Plugins.Native
{
public enum StringEncoding
{
Ansi,
Unicode,
MirandaDefault
}
public struct UnmanagedStringHandle : IUnmanagedMemoryHandle
{
#region Fields
private IntPtr intPtr;
public static readonly UnmanagedStringHandle Empty = new UnmanagedStringHandle();
private string originalString;
private StringEncoding encoding;
#endregion
#region .ctors
public UnmanagedStringHandle(string str, StringEncoding encoding)
{
reEval:
switch (encoding)
{
case StringEncoding.Unicode:
this.intPtr = Marshal.StringToHGlobalUni(str);
break;
case StringEncoding.Ansi:
this.intPtr = Marshal.StringToHGlobalAnsi(str);
break;
default:
encoding = MirandaEnvironment.MirandaStringEncoding;
if (encoding == StringEncoding.MirandaDefault)
throw new ArgumentException(TextResources.ExceptionMsg_CannotDetectMirandaDefaultStringEncoding);
goto reEval;
}
this.originalString = str;
this.encoding = encoding;
}
#endregion
#region Properties
public string OriginalString
{
get { return originalString; }
}
public StringEncoding Encoding
{
get
{
return encoding;
}
}
public IntPtr IntPtr
{
get { return intPtr; }
}
public static implicit operator IntPtr(UnmanagedStringHandle operand)
{
return operand.IntPtr;
}
[CLSCompliant(false)]
public static implicit operator UIntPtr(UnmanagedStringHandle operand)
{
return Translate.ToHandle(operand.IntPtr);
}
public int Size
{
get
{
if (!IsValid)
return 0;
switch (encoding)
{
case StringEncoding.Ansi:
return System.Text.Encoding.Default.GetByteCount(originalString);
case StringEncoding.Unicode:
return System.Text.Encoding.Unicode.GetByteCount(originalString);
default:
return -1;
}
}
}
public bool IsValid
{
get
{
return (intPtr != IntPtr.Zero);
}
}
#endregion
#region Methods
public void Free()
{
if (IsValid)
{
Marshal.FreeHGlobal(intPtr);
intPtr = IntPtr.Zero;
}
}
void IDisposable.Dispose()
{
Free();
}
#endregion
}
}
@@ -0,0 +1,211 @@
/***********************************************************************\
* Virtuoso.Miranda.Plugins (Hyphen) *
* Provides a managed wrapper for API of IM client Miranda. *
* Copyright (C) 2006-2009 virtuoso *
* deml.tomas@seznam.cz *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
* License as published by the Free Software Foundation; either *
* version 2.1 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
\***********************************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using Virtuoso.Miranda.Plugins.Infrastructure;
namespace Virtuoso.Miranda.Plugins.Native
{
public enum MarshalKind
{
Copy,
PinBlittable
}
public struct UnmanagedStructHandle<T> : IUnmanagedMemoryHandle
{
#region Fields
public readonly static UnmanagedStructHandle<T> Empty = new UnmanagedStructHandle<T>();
private Type ActualType;
private MarshalKind MarshalKind;
private GCHandle GcHandle;
private IntPtr intPtr;
private IntPtr SinglePressure;
private IntPtr[] Pressure;
#endregion
#region .ctors
public UnmanagedStructHandle(ref T structure)
: this(ref structure, MarshalKind.Copy, null)
{ }
public UnmanagedStructHandle(ref T structure, IntPtr pressure)
: this(ref structure, MarshalKind.Copy, null)
{
this.SinglePressure = pressure;
}
public UnmanagedStructHandle(ref T structure, params IntPtr[] pressure)
: this(ref structure, MarshalKind.Copy, pressure)
{ }
public UnmanagedStructHandle(ref T structure, MarshalKind marshalKind)
: this(ref structure, marshalKind, null)
{ }
public UnmanagedStructHandle(ref T structure, MarshalKind marshalKind, IntPtr pressure)
: this(ref structure, marshalKind, null)
{
this.SinglePressure = pressure;
}
public UnmanagedStructHandle(ref T structure, MarshalKind marshalKind, params IntPtr[] pressure)
{
// The structure is of a reference type and is null...
if (!typeof(T).IsValueType && object.ReferenceEquals(structure, null))
throw new ArgumentNullException("structure");
this.SinglePressure = IntPtr.Zero;
this.Pressure = pressure;
this.MarshalKind = marshalKind;
this.ActualType = structure.GetType();
switch (marshalKind)
{
case MarshalKind.Copy:
this.intPtr = Marshal.AllocHGlobal(Marshal.SizeOf(ActualType));
Marshal.StructureToPtr((object)structure, this.intPtr, false);
this.GcHandle = new GCHandle();
break;
case MarshalKind.PinBlittable:
this.GcHandle = GCHandle.Alloc((object)structure, GCHandleType.Pinned);
this.intPtr = this.GcHandle.AddrOfPinnedObject();
break;
default:
throw new ArgumentOutOfRangeException("marshalKind");
}
}
#endregion
#region Operator overloads
public static implicit operator IntPtr(UnmanagedStructHandle<T> operand)
{
return operand.IntPtr;
}
[CLSCompliant(false)]
public static implicit operator UIntPtr(UnmanagedStructHandle<T> operand)
{
return Translate.ToHandle(operand.IntPtr);
}
#endregion
#region Properties
public IntPtr IntPtr
{
get
{
return intPtr;
}
}
#endregion
#region Methods
public void MarshalBack(out T destination)
{
if (MarshalKind == MarshalKind.PinBlittable)
destination = (T)GcHandle.Target;
else
destination = (T)Marshal.PtrToStructure(IntPtr, ActualType);
}
public override int GetHashCode()
{
return intPtr.GetHashCode();
}
public override bool Equals(object obj)
{
if (obj == null || !(obj is UnmanagedStructHandle<T>))
return false;
return Equals((UnmanagedStructHandle<T>)obj);
}
public bool Equals(UnmanagedStructHandle<T> other)
{
return (other.intPtr == this.intPtr && other.Pressure == this.Pressure && other.SinglePressure == this.SinglePressure);
}
#endregion
void IDisposable.Dispose()
{
Free();
}
public void Free()
{
try
{
if (IntPtr != IntPtr.Zero)
{
FreePressure();
if (MarshalKind == MarshalKind.PinBlittable)
GcHandle.Free();
else
Marshal.DestroyStructure(IntPtr, ActualType);
intPtr = IntPtr.Zero;
ActualType = null;
}
}
catch (Exception e)
{
Log.DebuggerWrite(100, GetType().FullName, "Unable to free a struct handle: " + e.ToString());
}
}
private void FreePressure()
{
if (SinglePressure != IntPtr.Zero)
{
Marshal.FreeHGlobal(SinglePressure);
SinglePressure = IntPtr.Zero;
}
if (Pressure != null)
{
for (int i = 0; i < Pressure.Length; i++)
{
IntPtr ptr = Pressure[i];
if (ptr != IntPtr.Zero)
Marshal.FreeHGlobal(ptr);
}
Pressure = null;
}
}
}
}