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 / Languages / Managed C++ / May 2004

Tip: Looking for answers? Try searching our database.

Confused about __crt_dll_terminate

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Steve Baer - 11 May 2004 18:26 GMT
I'm wrapping unmanaged C++ classes using the standard managed C++ approach.
i.e. a __gc class that contains an internal pointer to an unmanaged class.
The purpose is to generate a .NET class library from our unmanaged class
library.

There are static unmanaged classes in this library, so I'm following the
MSFT approach of creating static functions that call __crt_dll_initialize at
startup and __crt_dll_terminate at the end of the calling application. My
problem occurs when I call the __crt_dll_terminate function at the end of my
test application. Immediately after this function gets called, the garbage
collector cleans up wrapper classes.

WrapperClass::~WrapperClass(){
 if(m_ptr) delete m_ptr; //delete internal unmanaged class
 m_ptr=NULL;
}

The wrapper class finalizer throws a NullPointer exception when I attempt to
delete the internal pointer. If I remove the call to __crt_dll_terminate,
everything works fine. I guess I'm confused as to what to do about this.

Thanks for any help in advance,
-steve
S. Han - 13 May 2004 01:13 GMT
If you write your own destructor you must suppress the GC finalizer.
So In your Wrapper class, override Dispose method:
public void Dispose()
{ // ... do your clean up
 GC.SuppressFinalize(this);
}

Signature

This posting is provided "AS IS" with no warranties, and confers no rights.

> I'm wrapping unmanaged C++ classes using the standard managed C++
> approach.
[quoted text clipped - 23 lines]
> Thanks for any help in advance,
> -steve

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.