473,662 Members | 2,524 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Confused about __crt_dll_termi nate

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_initi alize at
startup and __crt_dll_termi nate at the end of the calling application. My
problem occurs when I call the __crt_dll_termi nate 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_termi nate,
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 1500
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.SuppressFina lize(this);
}

--

This posting is provided "AS IS" with no warranties, and confers no rights.
"Steve Baer" <st***@nospam.o rg> wrote in message
news:10******** *****@corp.supe rnews.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_initi alize
at
startup and __crt_dll_termi nate at the end of the calling application. My
problem occurs when I call the __crt_dll_termi nate 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_termi nate,
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
5474
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 reference. However, when the object is a number, the story is so different. I don't understantd for what reason Python deals with them differently. The example is as follows: >>> a = >>> b = a
2
2612
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): funcname = 'do_' + cmd if hasattr(self, funcname): getattr(self, funcname)()
11
4942
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., http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&selm=Tidy7IDbDHA.2108%40cpmsftngxa06.phx.gbl) that indicate that ASP will queue up requests when they come in with the same "session".
6
1618
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. I am a bit confused as whether I have to run XT processor each time I update the XML file. Or is the does the web browser come with XT processor which will automatically load the xml document and transform it using an XSLT?
5
2783
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 system.mdw file, I get the "Current user account doesn't have permission to covert or enable this database".
1
3257
by: Benny Ng | last post by:
Hi,All, Export Method: ------------------------------------------------------------------------- strFileNameExport = "Results" Response.Clear() Response.Buffer = True Response.ContentType ="application/vnd.ms-excel" 'application/msword
2
2055
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 (non-.Net) if I wanted to fill a list it may look something like this: -------START CODE <%
11
3907
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 to do some example to explain, However, after some trying, I confused when I try to do some integer constant division, I know I should do float division something like 3.0/6.0, but I'm still confused where the -0.124709 comes for the following...
2
6825
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 form every thing works fine: checking items by code
0
8432
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8857
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8764
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8633
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7367
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6186
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4347
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1993
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1752
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.