get selected Mail Item in Outlook

S

Strader

Hello,

I need help to get the selected Mail Item in a C++ ALT Com Addin.
My Code so far

CComPtr<Outlook::MAPIFolder> mpFolder;
m_spExplorer->get_CurrentFolder(&mpFolder);
OlItemType pItem;
mpFolder->get_DefaultItemType(&pItem);

if(pItem == olMailItem)
{
CComPtr<Outlook::_MailItemPtr> spMailItem;
CComPtr<Outlook::Selection> spSelection;

m_spExplorer->get_Selection(&spSelection);
long itemsSelected;
spSelection->get_Count(&itemsSelected);
if(itemsSelected != 1)
return;

But I have a problem to cast the selected item in to a MailItem.

Any help is appreciated,

Thoma
 
M

Mike Walker [MVP]

Hi

Looking quickly at the code, you are not getting the ActiveExplorer but are
creating a folder this will create a new explorer of the type you are
looking for, the whole code snippet isn't present and am not a C++
programmer but looking between the lines this is probably the issue as will
not be the selected item

Regards

Mike Walker MVP
Visual Developer VSTO
 
S

Strader

Hi,

I use the m_spExplorer->get_CurrentFolder(&mpFolder) and mpFolder-
get_DefaultItemType(&pItem) to determine if the currend folder is
mail folder. If it is I get pe
m_spExplorer->get_Selection(&spSelection) the selected items.

The problem is now to get the item cast in a mail item.
If it try

CComPtr<Outlook::_MailItem> spMailItem;
spSelection->Item(index,&spMailItem);
I get a error message
'Outlook::Selection::Item': Konvertierung des Parameters 2 vo
'Outlook::_MailItem ** ' in 'IDispatch ** ' nicht möglich

Thanks for your help;

Thoma
 

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