gpt4 book ai didi

c++ - 捕获 Outlook 事件

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:54:22 25 4
gpt4 key购买 nike

我正在尝试使用 MFC 应用程序捕获一些 outlook 事件。我从这个Code Project开始样本。我设法捕获了电子邮件发送和接收事件,但无法捕获 ObjectSync.Start/End 事件。我相信我错过了一些东西。

这是QueryInterface方法:

STDMETHODIMP CAppEventListener::QueryInterface(REFIID riid, 
void ** ppvObj)
{
if (riid == IID_IUnknown){*ppvObj = static_cast<IUnknown*>(this);}
else
if (riid == IID_IDispatch){*ppvObj = static_cast<IDispatch*>(this);}
else
if (riid == IID_ApplicationEvents){*ppvObj = static_cast<IDispatch*>(this);}
else {*ppvObj = NULL;return E_NOINTERFACE;}
static_cast<IUnknown*>(*ppvObj)->AddRef();
return S_OK;
}

这是Invoke方法

STDMETHODIMP CAppEventListener::Invoke(DISPID dispIdMember, 
REFIID riid, LCID lcid,
WORD wFlags, DISPPARAMS* pDispParams,
VARIANT* pVarResult, EXCEPINFO* pExcepInfo,
UINT* puArgErr)
{
//declaratin of l_date and l_time
switch(dispIdMember)
{
case 0x0000fba7: HandleItemLoad(dispIdMember,l_date ,l_time);
break;

case 0x0000fab5: HandleOnReceive(riid,pDispParams,l_date ,l_time);
break;

case 0x0000f002: HandleOnSend(riid,pDispParams,l_date ,l_time);
break;

case 0x0000fb40: HandleContextMenuDis(dispIdMember,l_date ,l_time);
break;

case 0x0000fba6: HandleContextMenuClo(dispIdMember,l_date ,l_time);
break;

case 0x0000f006: HandleStartup(dispIdMember,l_date ,l_time);
break;

case 0x0000f007: HandleQuit(dispIdMember,l_date ,l_time);
break;

default: HandleUnknown(dispIdMember,l_date ,l_time);
break;
}
return S_OK;
}

这里是AttachToSource方法

STDMETHODIMP CAppEventListener::AttachToSource
( IUnknown* pEventSource )
{
HRESULT hr = S_OK;

IConnectionPointContainer* pCPC = NULL;
hr = pEventSource->QueryInterface( IID_IConnectionPointContainer,
(void**)&pCPC );
if (SUCCEEDED(hr))
{
hr = pCPC->FindConnectionPoint( IID_ApplicationEvents,
&m_pConnectionPoint );
if (SUCCEEDED(hr))
{
hr = m_pConnectionPoint->Advise( this, &m_dwConnection );
}
pCPC->Release();
}
return hr;
}

如有任何帮助,我们将不胜感激。


更新 1:

现在我有一个 SyncObjectEvents 的包装器类

class CSyncObjectEventListener : public IDispatch

这是我的 AttachToSource 方法:

HRESULT STDMETHODCALLTYPE CSyncObjectEventListener::AttachToSource( IUnknown* pEventSource )
{
HRESULT hr = S_OK;

IConnectionPointContainer* pCPC = NULL;
hr = pEventSource->QueryInterface( IID_IConnectionPointContainer,
(void**)&pCPC );
if (SUCCEEDED(hr))
{
HRESULT hr = pCPC->FindConnectionPoint(IID_SyncObjectEvents, &m_pConnectionPoint);
//Failure
if (SUCCEEDED(hr) )
{
hr = m_pConnectionPoint->Advise( this, &m_dwConnection );
}
pCPC->Release();
}

return hr;
}

IID_SyncObjectEvents 是这样定义的:

const IID IID_SyncObjectEvents  =   {0x00063005,0x0000,0x0000,{0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x46}};

FindConnectionPoint 方法连接失败。


更新 2:

我有另一个名为 ObjectSync 的类:class CObjectSync : public COleDispatchDriver在 CSyncObjectEventListener 类中,我有这个属性 public : CObjectSync m_pObjectSync;

这是我尝试连接的代码。

m_pSyncObjectEventListener = new CSyncObjectEventListener();
if(!m_pSyncObjectEventListener->m_pObjectSync.CreateDispatch( _T("Outlook.SyncObjects" ),&l_oleExcep))
{
return 0;
}

m_pSyncObjectEventListener->AddRef();
m_pSyncObjectEventListener->AttachToSource( m_pSyncObjectEventListener->m_pObjectSync.m_lpDispatch);

最佳答案

您的代码仅处理应用程序事件。您需要检索 SyncObject 对象并连接到它的事件 (SyncObjectEvents),而不是 _ApplicationEvents。

关于c++ - 捕获 Outlook 事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19561767/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com