Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / September 2007

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
whagedorn - 21 Sep 2007 07:29 GMT
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
G Himangi - 21 Sep 2007 09:38 GMT
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.ssware.com
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
---------

> Hi,
>
[quoted text clipped - 25 lines]
> Thanks,
> Wilfried
whagedorn - 21 Sep 2007 10:03 GMT
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.

> Yes, the garbage collector runs at random times. You can explicitly
> release the COMobject in C# by calling Marshal.ReleaseComObject.
[quoted text clipped - 40 lines]
>> Thanks,
>> Wilfried
Christian Fröschlin - 21 Sep 2007 14:54 GMT
> 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 - 24 Sep 2007 09:07 GMT
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

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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.