0
我正在开发用于VC6和VC9的VC加载项。以下代码来自我的作品。在CViaDevStudio::Evaluate
之后,我打电话给pDebugger->Release()
,一切正常。但在CViaVisualStudio::ReadFromMemory
中,在我拨打pDebugger->Release()
或pProc->Release()
后,VC9会提示错误提示错误号码未指定。我不知道为什么。我认为在使用COM对象后调用Release()
是合理的。为什么我不能调用发布COM对象的接口
/* 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;
}
非常感谢! – 2010-10-08 02:17:59