4

我正在尝试使用 MFC 应用程序捕获一些 Outlook 事件。我从这个代码项目示例开始。我设法捕获电子邮件发送和接收事件,但无法捕获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;
}

这是调用方法

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);
4

1 回答 1

4

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

于 2013-10-24T14:31:02.993 回答