Group:  Microsoft Outlook ยป microsoft.public.outlook.program_addins
Thread: Problem getting Incoming Item in my Outlook Addin

Geek News

Problem getting Incoming Item in my Outlook Addin
"seby" <karioblue2005[ at ]yahoo.com> 5/6/2006 6:53:24 AM
This is a multi-part message in MIME format.

------=_NextPart_000_0012_01C670B8.3E3EE340
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

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 =3D spItems->raw_GetLast(&pDisp);
spMItem =3D pDisp;

the spMItem is always NULL , even though this is fired in Check New =
Mail event=20

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=20
spMItem =3D iDisp; // spMItem is NULL on incoming email =20

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

------=_NextPart_000_0012_01C670B8.3E3EE340
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2900.2802" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY>
<DIV><FONT face=3DArial size=3D2>It seems there is a bug in an =
addin i am=20
working on. While retrieving an incoming MailItem from outlook =
using=20
this code:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><A href=3D"outlook::_MailItemPtr"><FONT face=3DArial=20
size=3D2>Outlook::_MailItemPtr</FONT></A><FONT face=3DArial size=3D2> =
spMItem;<BR>hr =3D=20
spItems->raw_GetLast(&pDisp);<BR>spMItem =3D pDisp;<BR><BR>the=20
 spMItem is always NULL , even though this is fired in Check New =
Mail event=20
<BR></FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Q1: Shouldn't  GetLast be the last =
added item=20
aka new Email ?</DIV></FONT>
<DIV><FONT face=3DArial size=3D2>Q2: Since the same happens with =
OnAddItem,=20
OnItemChanged ...</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>OnItemChangedParameter ( IDispatch=20
iDisp)</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>{     // cast =
to=20
_MailItemPtr </FONT></DIV>
<DIV><FONT face=3DArial =
size=3D2>       spMItem =3D=20
iDisp;  //   spMItem is NULL on incoming=20
email   </FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>how can one get the New item (incoming =
message)=20
using this type of code (ATL/C++) in a spMItem</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Just looking for a simple reliable=20
solution</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Thank you</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>~SB</FONT></DIV><!-- / message -->
<DIV><FONT face=3DArial size=3D2></FONT> </DIV></BODY></HTML>

------=_NextPart_000_0012_01C670B8.3E3EE340--

Re: Problem getting Incoming Item in my Outlook Addin
"Dmitry Streblechenko" <dmitry[ at ]dimastr.com> 5/6/2006 5:44:45 PM
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" <karioblue2005[ at ]yahoo.com> wrote in message
news:%23Ek0HnNcGHA.4892[ at ]TK2MSFTNGP02.phx.gbl...
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


Home | Search | Terms | Imprint Contact
Newsgroups Reader - provided by WiredBox.Net