[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.interop

ASSERT in ~CCmdTarget after Drag&Drop between MFC and C#

whagedorn

9/21/2007 6:29:00 AM

Hi,

I have written a small test application, where I integrated a c#
forms-window in a mfc-application via COM Interop.
Everthing is running very well, but if I use Drag&Drop from the MFC-part to
the C# window I got a debug ASSERT
in the destructor of the CCmdTaget-Class, which is the baseclass of the
using COleDataSource-object.

CCmdTarget::~CCmdTarget()
{
#ifndef _AFX_NO_OLE_SUPPORT
if (m_xDispatch.m_vtbl != 0)
((COleDispatchImpl*)&m_xDispatch)->Disconnect();
ASSERT(m_dwRef <= 1); <=
m_dwRef is 3
#endif
m_pModuleState = NULL;
}

It seems, that the garbage collector will not release this object after
dropping it.
I try to realease it manually, but without any success.

Any ideas or suggestions are appreciated.

Thanks,
Wilfried

4 Answers

G Himangi

9/21/2007 8:39:00 AM

0

Yes, the garbage collector runs at random times. You can explicitly release
the COMobject in C# by calling Marshal.ReleaseComObject.

However, the problem may also be that you are using a delete on the
COleDataSource-object, instead of that, you should use InternalRelease.

---------
- G Himangi, Sky Software http://www....
Shell MegaPack : GUI Controls For Drop-In Windows Explorer like Shell
Browsing Functionality For Your App (.Net & ActiveX Editions).
EZNamespaceExtensions.Net : Develop namespace extensions rapidly in .Net
EZShellExtensions.Net : Develop all shell extensions,explorer bars and BHOs
rapidly in .Net
---------



"whagedorn" <whagedorn@jetter.de> wrote in message
news:eMrgqjB$HHA.3716@TK2MSFTNGP03.phx.gbl...
> Hi,
>
> I have written a small test application, where I integrated a c#
> forms-window in a mfc-application via COM Interop.
> Everthing is running very well, but if I use Drag&Drop from the MFC-part
> to
> the C# window I got a debug ASSERT
> in the destructor of the CCmdTaget-Class, which is the baseclass of the
> using COleDataSource-object.
>
> CCmdTarget::~CCmdTarget()
> {
> #ifndef _AFX_NO_OLE_SUPPORT
> if (m_xDispatch.m_vtbl != 0)
> ((COleDispatchImpl*)&m_xDispatch)->Disconnect();
> ASSERT(m_dwRef <= 1); <=
> m_dwRef is 3
> #endif
> m_pModuleState = NULL;
> }
>
> It seems, that the garbage collector will not release this object after
> dropping it.
> I try to realease it manually, but without any success.
>
> Any ideas or suggestions are appreciated.
>
> Thanks,
> Wilfried
>


whagedorn

9/21/2007 9:03:00 AM

0

The main problem is, that I don't have any access to the
COleDataSource-object, which is encapsulate
in a DragEventsArg-object on the c# side. It is further wrapped from the
interop layer ( e.g. COleConvert ), so there is no chance to release it from
the drop target.
I have tried to call GC.Collect() after setting the DragEventsArg-object to
null, but without any success.


"G Himangi" <info@ssware.com> schrieb im Newsbeitrag
news:OEfJjqC$HHA.4956@TK2MSFTNGP06.phx.gbl...
> Yes, the garbage collector runs at random times. You can explicitly
> release the COMobject in C# by calling Marshal.ReleaseComObject.
>
> However, the problem may also be that you are using a delete on the
> COleDataSource-object, instead of that, you should use InternalRelease.
>
> ---------
> - G Himangi, Sky Software http://www....
> Shell MegaPack : GUI Controls For Drop-In Windows Explorer like Shell
> Browsing Functionality For Your App (.Net & ActiveX Editions).
> EZNamespaceExtensions.Net : Develop namespace extensions rapidly in .Net
> EZShellExtensions.Net : Develop all shell extensions,explorer bars and
> BHOs rapidly in .Net
> ---------
>
>
>
> "whagedorn" <whagedorn@jetter.de> wrote in message
> news:eMrgqjB$HHA.3716@TK2MSFTNGP03.phx.gbl...
>> Hi,
>>
>> I have written a small test application, where I integrated a c#
>> forms-window in a mfc-application via COM Interop.
>> Everthing is running very well, but if I use Drag&Drop from the MFC-part
>> to
>> the C# window I got a debug ASSERT
>> in the destructor of the CCmdTaget-Class, which is the baseclass of the
>> using COleDataSource-object.
>>
>> CCmdTarget::~CCmdTarget()
>> {
>> #ifndef _AFX_NO_OLE_SUPPORT
>> if (m_xDispatch.m_vtbl != 0)
>> ((COleDispatchImpl*)&m_xDispatch)->Disconnect();
>> ASSERT(m_dwRef <= 1); <=
>> m_dwRef is 3
>> #endif
>> m_pModuleState = NULL;
>> }
>>
>> It seems, that the garbage collector will not release this object after
>> dropping it.
>> I try to realease it manually, but without any success.
>>
>> Any ideas or suggestions are appreciated.
>>
>> Thanks,
>> Wilfried
>>
>
>

Christian Fröschlin

9/21/2007 1:55:00 PM

0

> I have tried to call GC.Collect() after setting the
> DragEventsArg-object to null, but without any success.

That wouldn't help much unless you also
called GC.WaitForPendingFinalizers().

whagedorn

9/24/2007 8:08:00 AM

0

Hello Christian ,

I've tried several things to release the COM-Object, but I believe the main
problem is,
that I cannot get access to the wrapped interface itself.

Here's a c# code fragment of my project. The drop source is a
MFC-Application which
creates a COleDataSource object on the stack and calls then its DoDragDrop()
method.

void list_DragDrop(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(JVSDragDropFormat))
{
e.Data.SetData(JVSDragDropFormat, null);

// object data = e.Data.GetData(JVSDragDropFormat);
// data = null;

GC.Collect();
GC.WaitForPendingFinalizers();
}
}
Any ideas ?

Wilfried


"Christian Fröschlin" <froeschlin@mvtec.com> schrieb im Newsbeitrag
news:fd0ier$rga$1@svr7.m-online.net...
>> I have tried to call GC.Collect() after setting the DragEventsArg-object
>> to null, but without any success.
>
> That wouldn't help much unless you also
> called GC.WaitForPendingFinalizers().