473,387 Members | 1,742 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Confused about __crt_dll_terminate

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
Nov 17 '05 #1
1 1483
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);
}

--

This posting is provided "AS IS" with no warranties, and confers no rights.
"Steve Baer" <st***@nospam.org> wrote in message
news:10*************@corp.supernews.com...
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

Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Haoyu Zhang | last post by:
Dear Friends, Python assignment is a reference assignment. However, I really can't explain the difference in the following example. When the object is a list, the assignment seems to be a...
2
by: Brian Roberts | last post by:
I'm confused about the use of hasattr/getattr, or possibly namespaces. I know how to do this: class UnderstandThis(object): def do_foo(self): pass def do_bar(self): pass def doit(self, cmd):...
11
by: Ohaya | last post by:
Hi, I'm trying to understand a situation where ASP seems to be "blocking" of "queuing" requests. This is on a Win2K Advanced Server, with IIS5. I've seen some posts (e.g.,...
6
by: ree32 | last post by:
I am a bit confused with capabilities of XML. I have an XML document with information on images(photos). Is there way to use XSL/XSLT to create a page that will display the images as gallery. ...
5
by: Jeff Amiel | last post by:
Yes, I've read the FAQ's... I'm still confused. I'm trying to help out a buddy to extract data from an .mdb file that has special 'permissions' on it. If I try to open it with the standard...
1
by: Benny Ng | last post by:
Hi,All, Export Method: ------------------------------------------------------------------------- strFileNameExport = "Results" Response.Clear() Response.Buffer = True...
2
by: Daniel | last post by:
I'm new to .Net and all of its abilities so I hope this makes sense. Basically I'm confused on when is the appropriate time to use web forms controls vs. regular HTML. For example in ASP...
11
by: timmu | last post by:
Someone asked me a question about integer division and printf yesterday, I tell him he should do a casting to float/double before you do any interger division. But he doesn't think so, so I try...
2
by: Peter | last post by:
Hi, I have a problem with Listview using checkboxes. If i check items by code BEFORE the form is shown the Listview.Items are confused during the ItemChecked Event !!! After showing the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.