AtlUnadvise()... 
Author Message
 AtlUnadvise()...

Hi,

What are the implications of not calling AtlUnadvise() after a call to
AtlAdvise().  My object calls AtlAdvise() but I don't want to call
AtlUnadvise() to remove the connection.

Heres some code to explain why:

// being code

STDMETHODIMP CMySimpleObj::Send()
{

typedef IDispEventImpl<1, CMySimpleObj, &DIID__ITransferEvents,
&LIBID_TRANSFERLib, 1, 0> MyEventImpl;

CComPtr<ITransfer> pITransferObj;

 hr = pIPortalTransfer.CoCreateInstance(__uuidof(PortalTransfer));

 if(FAILED(hr))
  return hr;

 if(MyEventImpl::m_dwEventCookie != 0xFEFEFEFE)
 {
  MyEventImpl::DispEventUnadvise(pIPortalTransfer);
 }

 hr = MyEventImpl::DispEventAdvise(pITransfer);

 USES_CONVERSION;

 CComBSTR szPath(m_szPath);

// start a thread in Run() to do the transfer
hr = pITransfer->Run(szPath);

// should call AtlUnadvise() here

    return hr;

Quote:
}

// end code

the Run() method in ITransfer creates a thread when periodically updates a
view using event sink mechanism.  I don't want to call AtlUnadvise()
directly after run because I will loose the connection and thus I can't
update my view.  Any suggestions?

regards,
C.



Sun, 23 May 2004 19:35:09 GMT  
 AtlUnadvise()...
A call to Advise has to be matched by a call to Unadvise eventually,
otherwise your sink object cannot die (the server holds a reference on it).
But of course Advise does not need to be followed by Unadvice within the
same method call or something. It is quite normal to, say, create some
object when the program starts and advise a sink, and unadvise and release
the object before the program terminates. Or sink events from an ActiveX
control when a dialog is created (usually in WM_INITDIALOG handler) and
unadvise when the dialog is destroyed (in WM_DESTROY handler).

So by all means keep the sink advised, but make sure it is unadvised as part
of cleanup sequence.
--
With best wishes,
    Igor Tandetnik

"For every complex problem, there is a solution that is simple, neat, and
wrong." H.L. Mencken


Quote:
> Hi,

> What are the implications of not calling AtlUnadvise() after a call to
> AtlAdvise().  My object calls AtlAdvise() but I don't want to call
> AtlUnadvise() to remove the connection.

> Heres some code to explain why:

> // being code

> STDMETHODIMP CMySimpleObj::Send()
> {

> typedef IDispEventImpl<1, CMySimpleObj, &DIID__ITransferEvents,
> &LIBID_TRANSFERLib, 1, 0> MyEventImpl;

> CComPtr<ITransfer> pITransferObj;

>  hr = pIPortalTransfer.CoCreateInstance(__uuidof(PortalTransfer));

>  if(FAILED(hr))
>   return hr;

>  if(MyEventImpl::m_dwEventCookie != 0xFEFEFEFE)
>  {
>   MyEventImpl::DispEventUnadvise(pIPortalTransfer);
>  }

>  hr = MyEventImpl::DispEventAdvise(pITransfer);

>  USES_CONVERSION;

>  CComBSTR szPath(m_szPath);

> // start a thread in Run() to do the transfer
> hr = pITransfer->Run(szPath);

> // should call AtlUnadvise() here

>     return hr;
> }

> // end code

> the Run() method in ITransfer creates a thread when periodically updates a
> view using event sink mechanism.  I don't want to call AtlUnadvise()
> directly after run because I will loose the connection and thus I can't
> update my view.  Any suggestions?

> regards,
> C.



Mon, 24 May 2004 00:35:13 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. AtlUnadvise, when server program has been aborted!

 

 
Powered by phpBB® Forum Software