PC Review


Reply
Thread Tools Rate Thread

Capturing events with IDispEventSimpleImpl

 
 
framara
Guest
Posts: n/a
 
      18th May 2010
Hello, I want to creating an addin that captures when a {contact, calendar,
task, note} is {created, edited, removed}. I have the following code, to make
it shorter I removed all the code but the related to contact, since all types
will be the same I guess.

AutoSync.h
class ATL_NO_VTABLE AutoSync :
public wxPanel,
public IDispEventSimpleImpl<1, AutoSync, &__uuidof(Outlook::ItemsEvents)>,
public IDispEventSimpleImpl<2, AutoSync, &__uuidof(Outlook::ItemsEvents)>,
public IDispEventSimpleImpl<3, AutoSync, &__uuidof(Outlook::ItemsEvents)>
{
public:
....
void __stdcall OnItemAdd(IDispatch* Item); /* 0xf001 */
void __stdcall OnItemChange(IDispatch* Item); /* 0xf002 */
void __stdcall OnItemRemove(); /* 0xf003 */

BEGIN_SINK_MAP(AutoSync)
SINK_ENTRY_INFO(1, __uuidof(Outlook::ItemsEvents), 0xf001, OnItemAdd,
&OnItemsAddInfo)
SINK_ENTRY_INFO(2, __uuidof(Outlook::ItemsEvents), 0xf002, OnItemChange,
&OnItemsChangeInfo)
SINK_ENTRY_INFO(3, __uuidof(Outlook::ItemsEvents), 0xf003, OnItemRemove,
&OnItemsRemoveInfo)
END_SINK_MAP()

typedef IDispEventSimpleImpl<1, AutoSync, &__uuidof(Outlook::ItemsEvents)>
ItemAddEvents;
typedef IDispEventSimpleImpl<2, AutoSync, &__uuidof(Outlook::ItemsEvents)>
ItemChangeEvents;
typedef IDispEventSimpleImpl<3, AutoSync, &__uuidof(Outlook::ItemsEvents)>
ItemRemoveEvents;

private:
CComPtr<Outlook::_Items> m_contacts;
};


AutoSync.cpp
_NameSpacePtr pMAPI = OutlookWorker::GetInstance()->GetNameSpacePtr();


MAPIFolderPtr pContactsFolder = NULL;
HRESULT hr = NULL;

//get folders
if(pMAPI != NULL) {
pMAPI->GetDefaultFolder(olFolderContacts, &pContactsFolder);
}

//get items
if(pContactsFolder != NULL) pContactsFolder->get_Items(&m_contacts);

//dispatch events
if(m_contacts != NULL) {
//HERE COMES THE EXCEPTION
hr =
ItemAddEvents:ispEventAdvise((IDispatch*)m_contacts,&__uuidof(Outlook::ItemsEvents));
hr =
ItemChangeEvents:ispEventAdvise((IDispatch*)m_contacts,&__uuidof(Outlook::ItemsEvents));
hr =
ItemRemoveEvents:ispEventAdvise((IDispatch*)m_contacts,&__uuidof(Outlook::ItemsEvents));
}


and this defined somewhere else:
_ATL_FUNC_INFO OnItemsAddInfo = {CC_STDCALL,VT_EMPTY,1,{VT_DISPATCH}};
_ATL_FUNC_INFO OnItemsChangeInfo = {CC_STDCALL,VT_EMPTY,1,{VT_DISPATCH}};
_ATL_FUNC_INFO OnItemsRemoveInfo = {CC_STDCALL,VT_EMPTY,0};

When the instructions:
hr =
ItemAddEvents:ispEventAdvise((IDispatch*)m_contacts,&__uuidof(Outlook::ItemsEvents));
hr =
ItemChangeEvents:ispEventAdvise((IDispatch*)m_contacts,&__uuidof(Outlook::ItemsEvents));
hr =
ItemRemoveEvents:ispEventAdvise((IDispatch*)m_contacts,&__uuidof(Outlook::ItemsEvents));

are executed, an excetion comes in atlbase.inl' when executes method 'Advise':

ATLINLINE ATLAPI AtlAdvise(IUnknown* pUnkCP, IUnknown* pUnk, const IID& iid,
LPDWORD pdw)
{
if(pUnkCP == NULL)
return E_INVALIDARG;

CComPtr<IConnectionPointContainer> pCPC;
CComPtr<IConnectionPoint> pCP;
HRESULT hRes = pUnkCP->QueryInterface(__uuidof(IConnectionPointContainer),
(void**)&pCPC);
if (SUCCEEDED(hRes))
hRes = pCPC->FindConnectionPoint(iid, &pCP);
if (SUCCEEDED(hRes))
//HERE GIVES EXCEPTION
//Unhandled exception at 0x2fe913e3 in OUTLOOK.EXE: 0xC0000005:
//Access violation reading location 0xcdcdcdcd.
hRes = pCP->Advise(pUnk, pdw);
return hRes;
}

Any idea or suggestion here? Thank you.
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Capturing First Few Ke Down Events fripper Microsoft Dot NET 0 22nd Oct 2008 02:18 AM
Capturing events Charles Jenkins Microsoft Dot NET Compact Framework 7 14th Nov 2006 04:32 AM
capturing VSS 6.0 events thro c# .net Aravind Sekar Microsoft Dot NET 0 30th Jun 2006 06:52 AM
Getting no Events ! - IDispEventSimpleImpl , DispEventAdvise davidb Microsoft Outlook Program Addins 3 13th Jun 2006 08:31 AM
Help with capturing events. vbMark Microsoft Dot NET Compact Framework 4 2nd Feb 2005 03:46 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:07 PM.