捕获自动发现完成事件
Capturing AutoDiscoverComplete event
我使用以下代码来捕获帐户自动发现完成事件。运行捕获此事件的线程时,我收到访问冲突错误,QueryInterface 方法失败。问题可能出在哪里?
DWORD WINAPI CaptureAccountDiscovery(LPVOID param)
{
CoInitialize(NULL);
CComPtr<Outlook::_Application> spApplication;
HRESULT hr = spApplication.CoCreateInstance(__uuidof(Outlook::Application), 0, CLSCTX_LOCAL_SERVER );
if(SUCCEEDED(hr) && spApplication)
{
CComPtr<Outlook::_NameSpace> spSession;
hr = spApplication->get_Session(reinterpret_cast<Outlook::_NameSpace **>(&spSession));
if (SUCCEEDED(hr) && spSession)
{
CComPtr<Outlook::_Accounts> spAccounts;
hr = spSession->get_Accounts(reinterpret_cast<Outlook::_Accounts **>(&spAccounts));
if (SUCCEEDED(hr) && spAccounts)
{
VARIANT index;
index.intVal = 1;
index.vt = VT_INT;
CComPtr<Outlook::_Accounts> spAccounts;
hr = spAccounts->Item(index, reinterpret_cast<Outlook::_Account **>(&spAccounts));
if (SUCCEEDED(hr) && spAccounts)
{
CComPtr<IConnectionPointContainer> spContainer;
HRESULT hr = spAccounts->QueryInterface(__uuidof(IConnectionPointContainer),reinterpret_cast<void **>(&spContainer));
if (SUCCEEDED(hr) && spContainer)
{
HANDLE hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
CComPtr<CAccountDiscover> spSink = new CAccountDiscover(hEvent);
CComPtr<IConnectionPoint> spConnectionPoint;
hr = spContainer->FindConnectionPoint(Outlook::CLSID_Accounts, &spConnectionPoint);
if (SUCCEEDED(hr) && spConnectionPoint)
{
DWORD dwCookie = 0;
CComPtr<IUnknown> spUnknown;
hr = spConnectionPoint->QueryInterface(IID_IUnknown, reinterpret_cast<void **>(&spUnknown));
if (SUCCEEDED(hr) && spUnknown)
{
hr = spConnectionPoint->Advise(spSink, &dwCookie);
if (SUCCEEDED(hr))
{
while(true)
{
MSG Message;
while(PeekMessage(&Message, NULL, WM_NULL, WM_NULL, PM_REMOVE))
{
TranslateMessage(&Message);
DispatchMessage(&Message);
}
DWORD dwStatus = WaitForSingleObject(hEvent, 0);
Sleep(1);
}
spConnectionPoint->Unadvise(dwCookie);
}
}
}
}
}
}
}
spApplication.Release();
}
CoUninitialize();
return 0;
}
代码
CComPtr<Outlook::_Accounts> spAccounts;
hr = spAccounts->Item(index, reinterpret_cast<Outlook::_Account **>(&spAccounts));
真的需要
CComPtr<Outlook::_Account> spAccount;
hr = spAccounts->Item(index, &spAccount);
请注意单数而不是复数。
相关文章:
- Android NDK传感器向事件队列报告奇怪的间隔
- 从文本文件中读取时钟时间和事件时间并进行处理
- WMI检测进程创建事件-c++
- EvtExportLogneneneba API正在将远程计算机的事件日志保存到远程PC本身.如何将其保存到主机
- 处理闪烁窗口事件
- C++Builder中的OnClick事件签名存在问题
- 跟踪滚动条上的鼠标事件
- 什么是事件表 (wxWidgets)?
- 如何在 MFCaptureEngine 中获取"Camera removed"事件
- 给定顺序中的事件处理
- 当服务中的事件被触发时,如何将响应从服务发送回客户端?
- 在 C++/CLI 中将 .NET 事件从一个 DLL 引发到另一个 DLL
- 如何创建事件驱动的 SDL2 应用程序
- Windows 进程间同步类似事件?
- 如何从C++端挂接到 QML 项的 onClick 事件
- 如何通过多类"Union variable" (sfml) 使用轮询事件
- 如何在Qt 4.8中阻止/忽略/丢弃早于特定超时的用户输入事件
- C++ 信号和插槽不工作:插槽不响应事件
- 在虚幻引擎中触发C++ dll的事件
- 捕获自动发现完成事件