cast problem in outlook selected item

G

Guest

Hello,

I try to get the Currently Selected Item in an Outlook Folder in a COM
addin. I have an example
(http://support.microsoft.com/default.aspx?scid=kb;en-us;241287) but it is
not a Com example.
My problem is now to cast the selected item in a mail or appointment or note
item.

if (strMessageClass == "IPM.Appointment") // A calendar entry was selected {
_AppointmentItem olAppointmentItem;
olAppointmentItem = (_AppointmentItem) olItem;
AfxMessageBox(olAppointmentItem.GetSubject());
AfxMessageBox(olAppointmentItem.GetBody());
}

How do I have to chance the code to be able to use it in my COM addin?

if (strMessageClass == "IPM.Appointment") // A calendar entry was selected
{
CComPtr<Outlook::_AppointmentItem> olAppointmentItem;


olAppointmentItem = (_AppointmentItem) olItem; ??????????????
AfxMessageBox(olAppointmentItem.GetSubject());
AfxMessageBox(olAppointmentItem.GetBody());
}


Thank you for your help,

Thomas
 
S

Sue Mosher [MVP-Outlook]

Check first to see what type of item it is. Here's a snippet from the code sample at http://www.outlookcode.com/codedetail.aspx?id=793:

// Check the ItemType, could be a MeetingAccept or something else
if (Item is Ol.MailItem )
{
// Cast to MailItem Object
Ol.MailItem myNewMail = (Ol.MailItem ) Item;

// Do something with Item
MessageBox.Show (myNewMail.Subject );
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top