我想在 Outlook 加载项中监控新的和更改的联系人
我用 C++ (VS6!) 创建了一个 Outlook 插件,用于监视 InspectorsCollection 以捕获用户何时打开或关闭联系人项目。效果很好。
现在我希望它能够跟踪用户何时保存新联系人或修改现有联系人。我想我应该修改 CInspectorsCollectionEventHandler 类来处理联系人项目。一切似乎都很好,FindConnectionPoint() 和 Advise() 成功,但我的 Invoke() 永远不会被调用。
当我的 dll 启动时,我的设置如下:
Outlook::MAPIFolderPtr pFolder = g_pNameSpace->GetDefaultFolder(Outlook::olFolderContacts);
if (pFolder != NULL) {
Outlook::_ItemsPtr pContactItems = pFolder->GetItems();
if (pContactItems != NULL)
m_pContactItemsEventHandler = new CItemsEventHandler(pContactItems);
}
我的 CItemsEventHandler 构造函数调用 SinkEvents() (如下),它可以正确执行。
以下是我的 CItemsEventHandler 类的关键部分:
STDMETHODIMP CItemsEventHandler::QueryInterface(REFIID riid, void** ppv)
{
if (NULL == ppv) return E_POINTER;
*ppv = NULL;
HRESULT hr = S_OK;
if ((__uuidof(Outlook::ItemsEvents) == riid) ||
(IID_IUnknown == riid) || (IID_IDispatch == riid))
*ppv = static_cast<IDispatch*>(this);
else
hr = E_NOINTERFACE;
if (NULL != *ppv)
reinterpret_cast<IUnknown*>(*ppv)->AddRef();
return hr;
}
void CItemsEventHandler::SinkEvents(LPDISPATCH pItems)
{
HRESULT hr;
// Get server's IConnectionPointContainer interface.
IConnectionPointContainer* pCPC;
hr = pItems->QueryInterface(IID_IConnectionPointContainer, (void **)&pCPC);
if (SUCCEEDED(hr)) {
// Find connection point for events we're interested in.
hr = pCPC->FindConnectionPoint(__uuidof(Outlook::ItemsEvents), &m_pConnection);
if (SUCCEEDED(hr))
{
AddRef();
hr = m_pConnection->Advise(static_cast<IDispatch*>(this), &m_dwCookie);
}
// Release the IConnectionPointContainer
pCPC->Release();
}
}
看起来一切都执行良好,并且代码基于有效的代码(对于检查器),但我只是没有收到任何对我的 Invoke() 的调用!有什么想法吗?
I've created an Outlook addin in C++ (VS6!) that monitors the InspectorsCollection to catch when a user opens or closes a contact item. Works great.
Now I want it to track when a user saves a new contact, or modifies an existing one. I figured I'd modify the CInspectorsCollectionEventHandler class to work with contact items. Everything seems to be ok, and FindConnectionPoint() and Advise() succeed, but my Invoke() never gets called.
Here's how I set up, when my dll starts up:
Outlook::MAPIFolderPtr pFolder = g_pNameSpace->GetDefaultFolder(Outlook::olFolderContacts);
if (pFolder != NULL) {
Outlook::_ItemsPtr pContactItems = pFolder->GetItems();
if (pContactItems != NULL)
m_pContactItemsEventHandler = new CItemsEventHandler(pContactItems);
}
My CItemsEventHandler constructor calls SinkEvents() (below), which executes correctly.
Here are the key parts of my CItemsEventHandler class:
STDMETHODIMP CItemsEventHandler::QueryInterface(REFIID riid, void** ppv)
{
if (NULL == ppv) return E_POINTER;
*ppv = NULL;
HRESULT hr = S_OK;
if ((__uuidof(Outlook::ItemsEvents) == riid) ||
(IID_IUnknown == riid) || (IID_IDispatch == riid))
*ppv = static_cast<IDispatch*>(this);
else
hr = E_NOINTERFACE;
if (NULL != *ppv)
reinterpret_cast<IUnknown*>(*ppv)->AddRef();
return hr;
}
void CItemsEventHandler::SinkEvents(LPDISPATCH pItems)
{
HRESULT hr;
// Get server's IConnectionPointContainer interface.
IConnectionPointContainer* pCPC;
hr = pItems->QueryInterface(IID_IConnectionPointContainer, (void **)&pCPC);
if (SUCCEEDED(hr)) {
// Find connection point for events we're interested in.
hr = pCPC->FindConnectionPoint(__uuidof(Outlook::ItemsEvents), &m_pConnection);
if (SUCCEEDED(hr))
{
AddRef();
hr = m_pConnection->Advise(static_cast<IDispatch*>(this), &m_dwCookie);
}
// Release the IConnectionPointContainer
pCPC->Release();
}
}
It looks like everything is executing fine, and the code is based on code that works (for Inspectors), but I just don't get any calls to my Invoke()! Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
解决了。希望这对某人有用。事实证明,一旦我的 pContactItems 指针超出范围(在使用它之后),就不会注册任何事件。我将 pContactItems 移至全局变量,它开始工作。
Solved it. Hope this is useful to someone. Turns out that as soon as my pContactItems pointer went out of scope (right after it was used), no events were registered. I moved pContactItems to a global variable and it started working.