A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Add-ins for Outlook
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Capturing events with IDispEventSimpleImpl



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old May 18th 10, 11:34 AM posted to microsoft.public.outlook.program_addins
framara
external usenet poster
 
Posts: 1
Default Capturing events with IDispEventSimpleImpl

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 IDispEventSimpleImpl1, AutoSync, &__uuidof(Outlook::ItemsEvents),
public IDispEventSimpleImpl2, AutoSync, &__uuidof(Outlook::ItemsEvents),
public IDispEventSimpleImpl3, 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 IDispEventSimpleImpl1, AutoSync, &__uuidof(Outlook::ItemsEvents)
ItemAddEvents;
typedef IDispEventSimpleImpl2, AutoSync, &__uuidof(Outlook::ItemsEvents)
ItemChangeEvents;
typedef IDispEventSimpleImpl3, AutoSync, &__uuidof(Outlook::ItemsEvents)
ItemRemoveEvents;

private:
CComPtrOutlook::_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_conta cts,&__uuidof(Outlook::ItemsEvents));
hr =
ItemChangeEvents:ispEventAdvise((IDispatch*)m_co ntacts,&__uuidof(Outlook::ItemsEvents));
hr =
ItemRemoveEvents:ispEventAdvise((IDispatch*)m_co ntacts,&__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_conta cts,&__uuidof(Outlook::ItemsEvents));
hr =
ItemChangeEvents:ispEventAdvise((IDispatch*)m_co ntacts,&__uuidof(Outlook::ItemsEvents));
hr =
ItemRemoveEvents:ispEventAdvise((IDispatch*)m_co ntacts,&__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;

CComPtrIConnectionPointContainer pCPC;
CComPtrIConnectionPoint 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.
Ads
 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Capturing Outlook Forms Events Duke2 Outlook - Using Forms 21 August 29th 09 02:07 AM
Capturing Outlook Forms Events Sue Mosher [MVP][_3_] Outlook - Using Forms 1 August 28th 09 08:25 PM
Capturing Send/Receive events in VSTO add-in Aakash Polra Outlook - General Queries 1 September 30th 08 05:49 PM
Getting no Events ! - IDispEventSimpleImpl , DispEventAdvise davidb Add-ins for Outlook 3 June 13th 06 08:31 AM
Capturing Message URL Avatar Outlook Express 7 January 30th 06 05:47 PM


All times are GMT +1. The time now is 05:14 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2024 Outlook Banter.
The comments are property of their posters.