visual studio 2008 - Why I cannot call the interface of Release of a COM object -


i'm develop vc add-in vc6 , vc9. following codes works. in cviadevstudio::evaluate, after call pdebugger->release() , it's ok. in cviavisualstudio::readfrommemory, after call pdebugger->release() or pproc->release(), vc9 prompt error complaint unspecified error number. don't know why. think it's reasonable call release() after have used com object.

/* 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:         // following code must called, otherwise vc6 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:     // don't know why following enclosed macros should not called. #if 0     if (pdebugger)         pdebugger->release();     if (pproc)         pproc->release(); #endif     return re; } 

envdte::debuggerptr pdebugger; 

note how declaration of pointer different way did in evaluate. idebugger* there. debuggerptr class wrapper class generated #import directive. smart pointer class, knows how call release() automatically. if code throws exceptions, won't leak pointer. highly recommended. you'll find documented in msdn library _com_ptr_t class.


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -