【发布时间】:2010-10-07 11:49:39
【问题描述】:
我正在为 VC6 和 VC9 开发一个 VC 插件。以下代码来自我的作品。在CViaDevStudio::Evaluate 中,在我致电pDebugger->Release() 之后,一切正常。但是在CViaVisualStudio::ReadFromMemory,当我调用pDebugger->Release()或者pProc->Release()之后,VC9会提示一个错误投诉一个未指定的错误号。我不知道为什么。我认为在我使用了 COM 对象之后调用Release() 是合理的。
/* VC6 */
class CViaDevStudio {
...
IApplication* m_pApplication;
};
BOOL CViaDevStudio::Evaluate(char* szExp, TCHAR* value, int size)
{
BOOL re = FALSE;
IDebugger* pDebugger = NULL;
m_pApplication->get_Debugger((IDispatch**)&pDebugger);
if (pDebugger) {
...
}
exit:
// The following code must be called, otherwise VC6 will complaint invalid access
// when it's started again
if (pDebugger)
pDebugger->Release();
return re;
}
/* VC9 */
class CViaVisualStudio {
...
CComPtr<EnvDTE::_DTE> m_pApplication;
};
BOOL CViaVisualStudio::ReadFromMemory(PBYTE pDst, PBYTE pSrc, long size)
{
BOOL re = FALSE;
EnvDTE::DebuggerPtr pDebugger;
EnvDTE::ProcessPtr pProc;
if (S_OK == m_pApplication->get_Debugger(&pDebugger)) {
if (S_OK == pDebugger->get_CurrentProcess(&pProc)) {
...
}
}
}
exit:
// I don't know why the following enclosed with macros should not be called.
#if 0
if (pDebugger)
pDebugger->Release();
if (pProc)
pProc->Release();
#endif
return re;
}
【问题讨论】:
标签: visual-studio-2008 visual-studio-addins