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

  • Thread starter Antonio Casilias
  • 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.
 
D

Dmitry Streblechenko

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
 

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