Problems with ItemAdd, ItemChange, ItemRemove events in VC++

K

kistvan

How should I use the ItemAdd, ItemChange, ItemRemove events in VC++ ? I have
an Outlook add-in where I want to use these events but there something is
wrong, the events are never triggered.

I found a lot of documentation and sample code in VB, where can I found
something in VC++ 6.0 ?

Thanks
 
K

kistvan

I resolved the problem, the problem was in the sink map, first I used
SINK_ENTRY_EX, when I modified it to SINK_ENTRY_INFO the application started
to work fine.

However I found a bug ( I don't know if this is a known issue or not ), when
I start to remove the items from the contacts folder the ItemRemove function
is called for every deleted item except the last contact. I reproduced this
problem several times.
Is this a bug ?

Thanks
 
D

Dmitry Streblechenko \(MVP\)

Not that I am aware of. Check if you can see the same problem in
OutlookSpy - click "Folder" button, select the Items property, click
"Browse", go to the Events tab. Do you see all the expected events being
raised as you delete the messages?

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

kistvan

No, for the last item in OutlookSpy the ItemRemove() event wasn't called.

The other two events ( ItemAdd and ItemChange ) are working for every item,
but the ItemRemove is not triggered for the last item ( at least I verified
with the contacts from the Contacts folder ).
 
D

Dmitry Streblechenko \(MVP\)

Fires just fine for me. Which version of Outlook are you using? Is it
running under Exchange or PST?

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

kistvan

I verified with Outlook 2000, XP and 2003 ( running under PST ) and on all
three versions the behavior is the same. When I deleted the last item
(contact item from the contacts folder) the ItemRemove() event is not
triggered.
( Ex: if I have 3 contacts, for 2 of them the ItemRemove event is triggered
but for the 3rd contact is not)

I verified this with appointments, tasks, notes and the problem reproducing.

Also I verified this on other machines and the problem reproduced ( I used
OutlookSpy everywhere to monitorize the events ).
 
D

Dmitry Streblechenko \(MVP\)

Hmmm... I can reproduce this problem under the PST provider (Exchange is
fine) - it looks like the PST provider contents table fires the
TABLE_ROW_DELETED notification for all rows except the last one. Deleting
the last row fires the TABLE_CHANGED event, which is not exposed in OOM.
I can't think of a simple workaround.

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

Sue Mosher [MVP-Outlook]

It's a known issue. I don't know of any workaround either.

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
R

Rob Charlton Jr.

I'm having the same problem too, I've developed a COM Add-In in VB and am tracing through all the events as I have the form linked to an Access table.

I did find a workaround, but I'm still debugging it, so I don't know if it's sound. This is the code that's in my Explorer's SelectionChange event:

Private Sub m_oExplorer_SelectionChange()

On Error Resume Next

Select Case True
Case Not m_bool_IsAFolderWithEventsIWantToTrack
Case Else

'Set m_oInspectors = m_oOutlook.Inspectors
Set m_oInspector = m_oOutlook.ActiveInspector
Set m_oContactItem = m_oOutlook.ActiveInspector.CurrentItem

Select Case True
Case m_oOutlook.ActiveExplorer.CurrentFolder.Items.Count = 0 _
And Not m_oContactItem Is Nothing

ContactDelete

Set m_oContactItem = Nothing

End Select

Select Case True
Case m_oOutlook.ActiveExplorer.Selection.Count > 0

Set m_oContactItem = m_oOutlook.ActiveExplorer.Selection(1)

End Select

End Select

End Sub

It's at the determination of the Items.Count = 0 and m_oContactItem Is Nothing, which is always triggered after the last contact in the PST file is deleted. This was the only method that I could figure out how to track when the last contact has "disappeared" without firing the event.


--
Thank You,

Robert L. Charlton, Jr.
 
S

Sue Mosher [MVP-Outlook]

That looks like a pretty good workaround. Thanks for sharing it!

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 

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