gpt4 book ai didi

c++ - Outlook进程无法退出

转载 作者:行者123 更新时间:2023-11-30 01:54:17 25 4
gpt4 key购买 nike

我正在开发一个与 MS Outlook(2007 和 2010)通信并捕获一些事件的应用程序(一个单独的 .exe)。使用 Outlook 2010 一切正常,但是使用 Outlook 2007 我注意到当我关闭 Outlook 时只有窗口被关闭,Outlook 进程继续运行。在显示任何代码之前,我想知道是否有人知道这种行为从何而来?注意,当我关闭我的应用程序时,Outlook 进程已停止。

这个link谈论类似的问题

更新

例如:这是我捕获应用程序事件的方式:(在我的主线程中)

CAppEventListener m_pAppEventListener = new CAppEventListener();
m_pAppEventListener->Initialize();

这里是 Initialize 方法的定义:

void CAppEventListener::Initialize()
{
COleException l_oleExcep;
BOOL bResult = m_OutlookApplicationInternal.CreateDispatch( _T("Outlook.Application"),&l_oleExcep );
//m_LogTrace = new CLogTrace();
//m_LogTrace->OnStartup(TRUE, TRUE);

if ( !bResult )
{
//CString l_csError;
//l_csError.Format("0x%08lx",l_oleExcep.m_sc);
//m_LogTrace->WriteLine("\tERROR\tEchec lors de l'appel de \"Create Dispatch\" code erreur "+l_csError);
//m_LogTrace->WriteLine("\tINFO\tFermeture d'IAOutlookMonior");
exit(0);
}

AddRef();
HRESULT hr = AttachToSource(m_OutlookApplicationInternal.m_lpDispatch );
//m_LogTrace->WriteLine(_T("\tINFO\tSuccès de connexion à Outlook"));
}

这是 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;
}

CAppEventListener 实现了 IDispatch 接口(interface)。 m_OutlookApplicationInternal 对象是 CApplication 类的一个实例。我该如何处理?

更新 2

如果我的应用程序进程在释放对 outlook 对象的引用之前被(意外地)终止,Outlook 将继续运行,不是吗?我该如何处理这个问题?

最佳答案

您需要确保您不会在任何延长的时间段内保留对任何 Outlook 对象的未完成引用 - 将所有变量设为方法的本地变量,创建 Outlook.Application 对象的实例等。完成后,释放所有对象(Marshal.ReleaseComObjects 如果您使用的是 .Net 效果很好)。

关于c++ - Outlook进程无法退出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22229036/

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