How to intercept the "ItemEvents"

A

Alexander Chen

I want to intercept Outlook::ItemEvents triggerd by _MailItem
objects in my addin,but I encounter a difficulty. if I use
IDispEventSimpleImpl or IDispEventImpl in my addin class, I must specify a
unique identifier for every _MailItem object. You know, the _MailItem object
does not like the button object, its number can change and it also can be
created or destroyed during using outlook, so I can not specify a identifier
for every _MailItem object when I implement my addin class.
Who can help me resolve this difficulty?
 
D

Dmitry Streblechenko \(MVP\)

If you want to intercept the events on all messages, you'd have to set
advise sinks on each message that you want to monitor, there is no way
around it.
What kind of events are you trying to intercept? If it is something caused
by a user, track Explorer.SelectionChange event, release old advise sinks,
then set new advise sinks on each selected message. Or you can use the
MAPIFolder.Items events on each folder that you are interested in.
And BTW, buttons are exactly like messages - you need to have separate
advise sinks for each instance of a button since you can have multiple
inspectors or explorers open.

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

Alexander Chen

Thanks for your zealousness.

I have resolved this problem. Just to implement an independent sink class
derived from IDispatch, then establish an advisory connection between the
connection point and the sink object for each _MailItem object. It doesn't
need use IDispEventSimpleImpl
or IDispEventImpl , so I does not encounter the problem about IDs anymore.
 
A

Alexander Chen

I want to ask you another question. you said "you need to have separately
advise sinks for each instance of a button since you can have multiple
inspectors or explorers open". But in my project, I can only advise sink
for a button once, although I have multiple inspectors open. If I adivise
sinks for each instance of a button in multiple inspectors, in the first
inpector,the button runs ok, but in the second inspector, the button will
respond for a click twice, in the third, it will respond the event thrice.
Why? By the way, I do not appoint tag for the button .
 
D

Dmitry Streblechenko \(MVP\)

You need to set the CommandBarButton.Tag property to a unique string for
each instance of the button.

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

Alexander Chen

If I don't set tag for each instance of the button, will it bring my addin
any bad influence ?
 
D

Dmitry Streblechenko \(MVP\)

You will get what you have now - your handler will be called multiple times.

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