I ask because I had a memory error when automating Excel, where if I
released the LPDISPATCH for the workbooks:
m_Workbook.ReleaseDispatch();
and then closed Excel from Excel, I got a memory error. However, if I
detach the LPDIPATCH:
m_Workbook.DetachDispatch();
the memory error disappears! I use ReleaseDispatch on all of the other
dispatches without a problem. Whats going on here? Do I need to use
them together?
m_Workbook.DetachDispatch();
m_Workbook.ReleaseDispatch();
Any insight is welcome.
DetachDispatch de-couples a COM IDispatch interface from an MFC
COleDispatchDriver wrapper class. (NB: In this case, when the
COleDispatchDriver class goes out of scope it won't automatically call
IDispatch::Release() as it normally would, seeing as it doesn't have an
IDispatch to release with :) )
You shouldn't need to use both of these together.
I use ReleaseDispatch all the time - I can't think of an instance when I'd
REALLY need to use DetachDispatch!! (Unless I wanted to use raw COM)
Check that you really need to use ReleaseDispatch() - the 2nd parameter of
COleDispatchDriver::AttachDispatch() specifies whether the class will do it
for you automatically (in the destructor).
If you have set the parameter to TRUE then you may be releasing more times
than necessary, causing the error.
--
Scott Tunstall
MFC & COM consultant
Personal URL: www.kwikrite.clara.net/bdash/
Curtis Wagner wrote in message <379C7D28...@eds.com>...