for (int i = 0; i < files.Length; i++)
{
MapiFileDesc fileDesc = new MapiFileDesc();
fileDesc.position = i;
fileDesc.fileName = Path.GetFileName(files[i]);
fileDesc.pathName = files[i];
Marshal.StructureToPtr(fileDesc, OffsetPtr(ptra, typeof(MapiFileDesc), files.Length - 1 - i), false);
}
return ptra;
}
private IntPtr GetRecipDesc()
{
IntPtr ptra = AllocMemory(typeof(MapiRecipDesc), 1);
MapiRecipDesc recipDesc = new MapiRecipDesc();
recipDesc.reserved = 0;
const int MAPI_TO = 1;
recipDesc.recipClass = MAPI_TO;
recipDesc.name = recipentName;
recipDesc.address = recipientAddress;
recipDesc.eIDSize = 0;
recipDesc.entryID = IntPtr.Zero;
Marshal.StructureToPtr(recipDesc, (IntPtr)ptra, false);
return ptra;
}
private IntPtr AllocMemory(Type structureType, int count)
{
return Marshal.AllocHGlobal(Marshal.SizeOf(structureType) * count);
}
private void Logoff()
{
if (session != IntPtr.Zero)
{
error = MAPILogoff(session, handle, 0, 0);
session = IntPtr.Zero;
}
}
private bool Logon(IntPtr hwnd)
{
this.handle = hwnd;
error = MAPILogon(hwnd, null, null, 0, 0, ref session);
if (error != 0)
error = MAPILogon(hwnd, null, null, MapiLogonUI, 0, ref session);
return error == 0;
}
private void DisposeMessage(MapiMessage msg)
{
FreeMemory(msg.files, typeof(MapiFileDesc), files.Length);
FreeMemory(msg.recips, typeof(MapiRecipDesc), 1);
msg = null;
}
/**//// <summary>
/// Release Resource
/// </summary>
/// <param name="ptr"></param>
/// <param name="structureType"></param>
/// <param name="count"></param>
private void FreeMemory(IntPtr ptr, Type structureType, int count)
{
if (ptr != IntPtr.Zero)
{
for (int i = 0; i < count; i++)
{
Marshal.DestroyStructure(OffsetPtr(ptr, structureType, i), structureType);
}
Marshal.FreeHGlobal(ptr);
}
}
}
}