How to distinguish _MailItem from ContactItem and other? (Outlook)

  • Thread starter Thread starter Antonio Casilias
  • Start date Start date
A

Antonio Casilias

Hi.
That's my code:

//-------------------------------------------------------

Outlook::_ExplorerPtr ouExp = spApp->ActiveExplorer();
Outlook::SelectionPtr ouSel;
ouExp->get_Selection(&ouSel);
long lCount;
ouSel->get_Count(&lCount);

// I need to run next part only for email messages not for contacts or tasks
in Outlook

for (long l = 1; l <= lCount; l++)
{
IDispatchPtr olDisp = ouSel->Item(_variant_t(l));
Outlook::_MailItemPtr olMail(olDisp);
IUnknownPtr olMsgUnk;
olMail->get_MAPIOBJECT(&olMsgUnk);
CComPtr<IMessage> olMapiMessage;
olMsgUnk->QueryInterface(IID_IMessage,
reinterpret_cast<void**>(&olMapiMessage));
// doing something with message
// removing MailItem
}

This is part of button click event hadler. It removes email messages. But if
I select in explorer one of contacts of tasks - it removes them too. How to
avoid this?
Thanks.
 
Use the Class property (all Outlook objects expose it). It is 43 for the
MailItem object, 40 for ContactItem, etc.
You will need to access that property using late binding
(IDispatch::GetIDsFromNames/Invoke)

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
Back
Top