Alex Abramov
Posts: 34
Joined: 2006-09-15
|
Hi,
I am trying to get individual attachment sizes.
I copied the code for the OlAttachment Example and the code fails
I then installed the OlAttachment example, and it's having the same problem.
When I call Marshal.QueryInterface(unkObje, ref iMapiProp, out unk)
the unk comes out with a zero value, so the code never gets to check the property.
I've saved the email, defined a separate attachment object, and even changed the GUID value (btw, should that be done always/never/doesn't matter? )
Here is my modified code: (I am trying to put attachment names and sized into a table)
private DataTable GetAttachmentInfo(Outlook.MailItem oItem)
{
oItem.Save();
// get attachment info
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[] { new DataColumn( "NAME", typeof(string) ),
new DataColumn( "SIZE", typeof(string) ) });
for (int i = 1; i <= oItem.Attachments.Count; i++)
{
IntPtr unk = IntPtr.Zero;
object mapiObject = null;
IntPtr unkObj = IntPtr.Zero;
Outlook.Attachment att = null;
try
{
att = oItem.Attachments.Item(i);
mapiObject = att.MAPIOBJECT;
unkObj = Marshal.GetIUnknownForObject(mapiObject);
Guid iMapiProp = new Guid("0002A305-0000-0000-C000-000000000046");
Marshal.QueryInterface(unkObj, ref iMapiProp, out unk);
if (unk != IntPtr.Zero)
{
IntPtr pPropValue = IntPtr.Zero;
try
{
// get size.
myMAPI.HrGetOneProp(unk, myMAPI.PR_ATTACH_SIZE, out pPropValue);
myMAPI.SPropValue propValue = (myMAPI.SPropValue)Marshal.PtrToStructure(pPropValue, typeof(myMAPI.SPropValue));
long size = 0; // propValue.Value;
dt.Rows.Add(new object[] { oItem.Attachments.Item(i).DisplayName, size.ToString() });
}
catch
{
}
if (pPropValue != IntPtr.Zero)
myMAPI.MAPIFreeBuffer(pPropValue);
}
}
catch
{
continue;
}
finally
{
if (unkObj != IntPtr.Zero)
Marshal.Release(unkObj);
if (unk != IntPtr.Zero)
Marshal.Release(unk);
if (mapiObject != null)
Marshal.ReleaseComObject(mapiObject);
if (att != null)
Marshal.ReleaseComObject(att);
}
}
return dt;
}
|
|
Sergey Grischenko
Add-in Express team
Posts: 7235
Joined: 2004-07-05
|
Hi Alex.
The Guid of the Attachment interface is '00020303-0000-0000-C000-000000000046'. Please use it in your code.
The OlAttachment example works fine on my PC. I have just test it again.
However if you use Exchange server you need to add the 'size &= 0xFFFFFFFF;' statement after the 'long size = propValue.Value;'.
Did you debug the example? What exactly doesn't work?
|
|
Alex Abramov
Posts: 34
Joined: 2006-09-15
|
I am using EMAPI for two things, to get the senders address and to get the attachment size. That's why I thought I should change the GUID so they don't clash. However, I changed it back, and it still has the same problem.
The issue is that when Marshal.QueryInterface(unkObje, ref iMapiProp, out unk) is called, the unk is returned as IntPtr.Zero, and never goes into the if statement to actually get the property. I had the same problem with your example, so it might be a specific issue to my machine.
It looks like the QueryInterface is failing, any way to work around that?
Thank you,
Alex Abramov |
|
Sergey Grischenko
Add-in Express team
Posts: 7235
Joined: 2004-07-05
|
Alex, can I test your code on my PC? |
|
Alex Abramov
Posts: 34
Joined: 2006-09-15
|
You want the whole addin?
If you're looking for the code of the function that fails, it's posted above. The only thing I changed is the guid to the one you suggested later.
I am having an issue with a different program where it cannot find MAPI32.dll in the registry, and I am working on that right not so see if that changes anything.
If you would like the entire plugin, let me have an email address to send the code to you.
Thank you,
Alex |
|
Sergey Grischenko
Add-in Express team
Posts: 7235
Joined: 2004-07-05
|
Alex, I have just sent you an email.
Please send me the add-in project. I will test it on my PC. |
|