Get Sender Address

Add-in Express™ Support Service
That's what is more important than anything else

Get Sender Address
How do I get senders address 
Alex Abramov




Posts: 34
Joined: 2006-09-15
Hi,

I just installed ADX.NET to replace my existing add-in which was experiencing performance and stability issues.

I am currenlty trying to work around two issues. The main one is getting to Extended MAPI properties, since MS was nice enought to leave them out of OOM.

I am trying to get the senders address. I wrote code based on examples provided in ADX toys, and it doesn't work. ADX toys don't work either, although I have not debugged them to check if it's the same problem. I receive the following error message: "Arithmetic operation resulted in an overflow."
The line that causes the error is this:
sender = Marshal.PtrToStringAnsi(new IntPtr(propValue.Value));

I am using C#/VS2005 for OL2002

Below is my code:
string sender = string.Empty;
if (Item is Outlook.MailItem)
{
IntPtr unk = IntPtr.Zero;
object mapiObject = null;
IntPtr unkObj = IntPtr.Zero;
try
{
mapiObject = (Item as Outlook.MailItem).MAPIOBJECT;
unkObj = Marshal.GetIUnknownForObject(mapiObject);
Guid iMapiProp = new Guid("00020303-0000-0000-C000-000000000046");
Marshal.QueryInterface(unkObj, ref iMapiProp, out unk);
if (unk != IntPtr.Zero)
{
IntPtr pPropValue = IntPtr.Zero;
try
{
myMAPI.HrGetOneProp(unk, myMAPI.PR_BODY, out pPropValue);
myMAPI.SPropValue propValue = (myMAPI.SPropValue)Marshal.PtrToStructure(pPropValue, typeof(myMAPI.SPropValue));
// this causes an error due to an artithmetic overflow
sender = Marshal.PtrToStringAnsi(new IntPtr(propValue.Value));
}
catch( Exception ex )
{
HandleException(ex, "GetMAPIProp");
}
if (pPropValue != IntPtr.Zero)
myMAPI.MAPIFreeBuffer(pPropValue);
}
}
catch (Exception ex)
{
HandleException(ex, "GetSender");
return string.Empty;
}
finally
{
if (unkObj != IntPtr.Zero)
Marshal.Release(unkObj);
if (unk != IntPtr.Zero)
Marshal.Release(unk);
if (mapiObject != null)
Marshal.ReleaseComObject(mapiObject);
}
}
return sender;

Thank you,

Alex

P.S. How do I get to the values stored in the Property Page?
Posted 15 Sep, 2006 18:22:31 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Hi Alex.

Please download a new edition of 'ADX Toys for Outlook' add-in here:
http://www.add-in-express.com/projects/oltoys-cs2005.zip

You can access the property page using the PageControl property of the addinmodule (an example here: http://www.add-in-express.com/projects/olnewpropertypage.zip)
Posted 18 Sep, 2006 08:11:11 Top
Alex Abramov




Posts: 34
Joined: 2006-09-15
Thanks that worked.
Another question:
If I would like to add a custom control to the project (derived from UserControl) should I give it a GUID and a progID? or just let the registration take care of that?

Thanks.
Posted 18 Sep, 2006 11:06:31 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Hi Alex.

If you are going to put the user control on the Property page, you don't need to register the control.
Posted 19 Sep, 2006 06:03:29 Top
Alex Abramov




Posts: 34
Joined: 2006-09-15
No, I have two forms in my project, one of them needs to list the attachment and let the user decide how to deal with each one individually (save to disk, delete, or leave as is) and I uses a custom control I created to provide a radio box group. This control is going to be repeated as many times on the form as there are attachments.

Do I need to register the forms, and/or the controls which are used in the forms?

Alex
Posted 19 Sep, 2006 08:52:22 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Alex, you don't need to register the form. Just use them "as is" in the add-in code.
Posted 19 Sep, 2006 12:20:27 Top