Re: COleDataSource
"RedLars" <Liverpool1892@gmail.com> ha scritto nel messaggio
news:4463e7a9-21aa-4fec-af81-3d666dfae6ae@c65g2000hsa.googlegroups.com...
COleDataSource * pDataSource = new COleDataSource;
// fill-in code
pDataSource->CacheGlobalData(...);
pDataSource->DoDragDrop ();
This code works! The correct data is transferred to the destination!
The problem now is cleaning up.
Adding a delete pDataSource causes an access violation in destination
code.
What I've noticed is that pDataSource->m_dwRef is increment to 1 on
creation and increased to 3 if OnDragEnter\OnDragDrop or OnDragEnter
\OnDragLeave occurs in destination code.
Those OLE objects are reference counted, so I would not call 'delete' on
them...
I would "respect" their contract of AddRef/Release (these are methods
present in IUknown, the root interface for COM/OLE objects).
Seen some code example use the following pattern:
pDataSource->DoDragDrop ();
if ( pDataSource->m_dwRef <= 1)
delete pDataSource;
else
pDataSource->ExternalRelease();
I would just call ->ExternalRelease (or InternalRelease, if there is no
aggregation).
I think that the difference between External and Internal is about
aggregation: External methods like ExternalRelease are to properly manage
aggregation.
pDataSource->DoDragDrop();
pDataSource->ExternalRelease();
// or
// pDataSource->InternalRelease();
// if there's no aggregation
I believe that Internal/ExternalRelease will decrement the reference count,
and call C++ 'delete' if reference count is 0.
However, I'm not sure about that, and I would prefer experimenting with some
real code, also considering that you are mixing MFC and managed world of
..NET here... (I think that computer science is an "experimental" science :)
we need compilers, debuggers, log files, etc. to diagnose things and try to
find solutions to bug.)
BTW: I would also post this question in the ATL group.
There is a COM very expert there whose name is Igor (T.): he knows a lot
about COM and OLE and I believe he will give you a detailed answer...
Giovanni