Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

detach dispatch vs release dispatch

362 views
Skip to first unread message

Curtis Wagner

unread,
Jul 26, 1999, 3:00:00 AM7/26/99
to
What are the settle differences between DetachDispatch, and
ReleaseDispatch?

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.

Scott Tunstall

unread,
Jul 27, 1999, 3:00:00 AM7/27/99
to
ReleaseDispatch calls IDispatch::Release() to reduce the associated
IDispatch interface's Reference count.

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>...

0 new messages