catch events of Ms outlook

  • Thread starter Thread starter Rohan lotlikat
  • Start date Start date
R

Rohan lotlikat

Hi,

How can i programmatically find out when a new contact is added in Ms
Outlook .

I have written a COM Addin in VC++ for Ms Outlook. And i want to perform
some operation when a new contact is added ..is it possible to capture that
event?

Regards
Rohan
 
Use the MAPIFolder.Items.Add event to monitor the Contacts folder for new items.
 
Hi,

Thanx for replying..

But how do you catch implement that event.I am little new to this. Could you
help me out in this..

Thnx
 
Can you provide more details on what you're trying to do? In what version of Outlook? And with what programming tools?
 
Hi Sue

I working on VC++ and the toolbar is for MS Outlook 2003.

So i want to perform a task when a new contact is added.

I tried following:

extern _ATL_FUNC_INFO OnItemAddInfo;


typedef IDispEventSimpleImpl<10006,CZOLAddin, &__uuidof(Outlook::ItemsEvents)
ItemEvent;

class ATL_NO_VTABLE CZOLAddin :
public CComObjectRootEx<CComSingleThreadModel>,
public CComCoClass<CZOLAddin, &CLSID_ZOLAddin>,
public ISupportErrorInfo,
public IDispatchImpl<IZOLAddin, &IID_IZOLAddin, &LIBID_ZEBOTOOLBARLib>,
public IDispatchImpl<_IDTExtensibility2, &IID__IDTExtensibility2,
&LIBID_AddInDesignerObjects>,
public InviteButtonEvent,
public HomePageMenuButtonEvent,
public HomePageButtonEvent,
public AboutButtonEvent,
public SearchComboEvent,
public ItemEvent

then onConnection i do this:

pApp->GetNamespace(L"MAPI",&nameSpace);


if(nameSpace){
nameSpace->get_CurrentUser(&CurUser);
CurUser->get_Name(&m_CurUserName);

nameSpace->GetDefaultFolder(olFolderContacts,&mFolder);
mFolder->get_Items(&m_spItems);

m_spItems is of type _ItemsPtr.

then i advise it

ItemEvent::DispEventAdvise((IDispatch*)m_spItems,
&__uuidof(Outlook::ItemsEvents));

the event handler is defined as :

void __stdcall CZOLAddin::OnItemAdd(IDispatch * Inspector)
{

MessageBeep(1);

}

but this does not work ..i tried keeping a break point ..but no luck.

can u guide me on this.

Regards
Rohan

}
 
Hey Sue

I figured it out.
I used
CComPtr<Outlook::_Items> m_spItems;
instead of : _ItemsPtr m_spItems;

It works fine now.

Thanks
Regards
Rohan.
 
Back
Top