Most likely that means the message is something other than MailItem. Note
that you can have objects rather than MailItem in your Inbox, e.g. NDRs,
meeting requests, etc.
Try to read the Class property first using late binding (all Outlook objects
support it). Regular mail items will have Class = 43.
Did you try to explicilty call iDisp.QueryInterface(...) to see if you
really get E_NOINTERFACE error?
Also note that Items.GetLast is not guarantee is not guaranteed to return
the last added item, so using Items.ItemAdd event on the Inbox or
Application.NewMailEx (Outlook 2003, passes the entry id which can be used
to call Namespace.GetItemFromID) could be a much better alternative.
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
"seby" wrote in message
...
It seems there is a bug in an addin i am working on. While retrieving an
incoming MailItem from outlook using this code:
Outlook::_MailItemPtr spMItem;
hr = spItems-raw_GetLast(&pDisp);
spMItem = pDisp;
the spMItem is always NULL , even though this is fired in Check New Mail
event
Q1: Shouldn't GetLast be the last added item aka new Email ?
Q2: Since the same happens with OnAddItem, OnItemChanged ...
OnItemChangedParameter ( IDispatch iDisp)
{ // cast to _MailItemPtr
spMItem = iDisp; // spMItem is NULL on incoming email
how can one get the New item (incoming message) using this type of code
(ATL/C++) in a spMItem
Just looking for a simple reliable solution
Thank you
~SB