All -
As we all know, Dispose method is reserved in C++ 8 and the expected syntax
is to use ~MyClass().
In 1.1, we used to have following structure for Dispose
[Code illustrated in C# for brevity:-)]
class MyClass : IDisposable
{
public void Dispose() { Dispose(true); GC.Supressxxx(t his); }
~Dispose() { Dispose(false); } // Finalizer
protected virtual void Dispose(bool disposing)
{
if(disposing) { xxx } // Disposing ilustrates if we are in finalizer
yyyy
}
}
System.Windows. Forms.Form used to have such a model, and we used it for our
finalizable classes to implement all cleanups in the single "protected
override Dispose(bool disposing)", which nicely has the "disposing" parameter.
Now C++ 8.0, disallows having any function by name Dispose and the structure
has to be changed with a new name (protected virtual "DisposeObj ect" for
instance)
The question is -
Why does the compiler forbids even overloaded Dispose [like Dispose(bool)]
methods. I can understand the reserved method for Dispose() but why for
overloads even?
If we simply re-compile our code with the new compiler (after syntax
changes), it we will break our clients. Clients will have to change their
code for overriding the Dispose method!
Any suggestions? [Using VS 2005 Beta 2]
Thanks in advance.
Regardz
Grafix. 13 1541
Hi Grafix! As we all know, Dispose method is reserved in C++ 8 and the expected syntax is to use ~MyClass().
In 1.1, we used to have following structure for Dispose [Code illustrated in C# for brevity:-)] class MyClass : IDisposable { public void Dispose() { Dispose(true); GC.Supressxxx(t his); } ~Dispose() { Dispose(false); } // Finalizer protected virtual void Dispose(bool disposing) { if(disposing) { xxx } // Disposing ilustrates if we are in finalizer yyyy } }
See: Destructors and Finalizers in Visual C++
http://msdn2.microsoft .com/en-us/library/ms177197
In short:
The Dispose-Pattern in 1.1 mapps to:
void Dispose(bool disposing) {
if (disposing) {
~T();
} else {
!T();
}
}
So you just need to implement ~T and !T and you have the desired behavior...
--
Greetings
Jochen
My blog about Win32 and .NET
http://blog.kalmbachne t.de/
Jochen -
If an assembly compiled with VC 2005 must be consumed by a C# assembly,
then how can they override the "Dispose(bo ol disposing)" method, becoz the
method "Dispose(bo ol)" is forbidden by C++?
My point is that if a (ref) class written in C++ , has both a finalizer and
a dispose method (for deterministic destruction), and a derived class (in
another language like C#) wanted to consume it, then overriding Dispose(bool
disposing) shows if we are in finalizer or not nicely, for the derived class.
C# client of MyClass
class CSharpClass : MyClass (see MyClass from OrigPosting sample)
{
protected override void Dispose(bool disposing)
{
if(disposing) // Got to know if we are disposing or not w.o any effort
{
}
base.Dispose(di sposing);
}
Now the C# class has found out if it is in finalizer or not *without* doing
any effort, by examinin the "disposing" parameter. C++ 2005 strips this
facility by making Dispose(bool) reserved!
Regardz
Grafix.
"Jochen Kalmbach [MVP]" wrote: Hi Grafix!
As we all know, Dispose method is reserved in C++ 8 and the expected syntax is to use ~MyClass().
In 1.1, we used to have following structure for Dispose [Code illustrated in C# for brevity:-)] class MyClass : IDisposable { public void Dispose() { Dispose(true); GC.Supressxxx(t his); } ~Dispose() { Dispose(false); } // Finalizer protected virtual void Dispose(bool disposing) { if(disposing) { xxx } // Disposing ilustrates if we are in finalizer yyyy } }
See: Destructors and Finalizers in Visual C++ http://msdn2.microsoft .com/en-us/library/ms177197
In short: The Dispose-Pattern in 1.1 mapps to:
void Dispose(bool disposing) { if (disposing) { ~T(); } else { !T(); } }
So you just need to implement ~T and !T and you have the desired behavior...
-- Greetings Jochen
My blog about Win32 and .NET http://blog.kalmbachne t.de/
Curiously enough, you can use "Dispose(Boolea n...".
For some reason the compiler reserves "Dispose(bool.. .)", but not
"Dispose(Boolea n...)", so there's your work-around.
--
David Anton www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C# to C++ converter & VB to C++ converter
Instant J#: VB to J# converter
"Grafix" wrote: All - As we all know, Dispose method is reserved in C++ 8 and the expected syntax is to use ~MyClass().
In 1.1, we used to have following structure for Dispose [Code illustrated in C# for brevity:-)] class MyClass : IDisposable { public void Dispose() { Dispose(true); GC.Supressxxx(t his); } ~Dispose() { Dispose(false); } // Finalizer protected virtual void Dispose(bool disposing) { if(disposing) { xxx } // Disposing ilustrates if we are in finalizer yyyy } }
System.Windows. Forms.Form used to have such a model, and we used it for our finalizable classes to implement all cleanups in the single "protected override Dispose(bool disposing)", which nicely has the "disposing" parameter.
Now C++ 8.0, disallows having any function by name Dispose and the structure has to be changed with a new name (protected virtual "DisposeObj ect" for instance)
The question is - Why does the compiler forbids even overloaded Dispose [like Dispose(bool)] methods. I can understand the reserved method for Dispose() but why for overloads even?
If we simply re-compile our code with the new compiler (after syntax changes), it we will break our clients. Clients will have to change their code for overriding the Dispose method!
Any suggestions? [Using VS 2005 Beta 2] Thanks in advance.
Regardz Grafix.
Hi Grafix! If an assembly compiled with VC 2005 must be consumed by a C# assembly, then how can they override the "Dispose(bo ol disposing)" method, becoz the method "Dispose(bo ol)" is forbidden by C++?
I don´t understand your problem...
For example, the following C++/CLI class:
public ref class ManagedClass
{
public:
ManagedClass()
{
}
~ManagedClass()
{
}
!ManagedClass()
{
}
};
will be represented in C# as:
public class ManagedClass : IDisposable
{
public ManagedClass();
private void ~ManagedClass() ;
private void !ManagedClass() ;
public sealed override void Dispose();
protected virtual void Dispose([MarshalAs(Unman agedType.U1)] bool);
protected override void Finalize();
}
So every C# class derived from ManagedClass can override "Dispose(bool)" ...
Or what is your problem?
My point is that if a (ref) class written in C++ , has both a finalizer and a dispose method (for deterministic destruction), and a derived class (in another language like C#) wanted to consume it, then overriding Dispose(bool disposing) shows if we are in finalizer or not nicely, for the derived class.
And this is possible... or maybe I misunderstood your problem...
--
Greetings
Jochen
My blog about Win32 and .NET http://blog.kalmbachnet.de/
Hi David! so there's your work-around.
Workaround for what? I don´t see a problem...
--
Greetings
Jochen
My blog about Win32 and .NET http://blog.kalmbachnet.de/
According to the original post:
"If we simply re-compile our code with the new compiler (after syntax
changes), it we will break our clients. Clients will have to change their
code for overriding the Dispose method"
Using "Boolean" instead of "bool" will mean that you don't break your
clients' code.
--
David Anton www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C# to C++ converter & VB to C++ converter
Instant J#: VB to J# converter
"Jochen Kalmbach [MVP]" wrote: Hi David!
so there's your work-around.
Workaround for what? I don´t see a problem...
-- Greetings Jochen
My blog about Win32 and .NET http://blog.kalmbachnet.de/
Actually, clients that are overriding Dispose(bool) will be trivially broken
since they'll have to change their overrides to Dispose(Boolean ).
But certainly clients' code that calls Dispose(bool) will not be broken
(since bool is identical to Boolean).
--
David Anton www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C# to C++ converter & VB to C++ converter
Instant J#: VB to J# converter
"Jochen Kalmbach [MVP]" wrote: Hi David!
so there's your work-around.
Workaround for what? I don´t see a problem...
-- Greetings Jochen
My blog about Win32 and .NET http://blog.kalmbachnet.de/
Hi David! According to the original post: "If we simply re-compile our code with the new compiler (after syntax changes), it we will break our clients. Clients will have to change their code for overriding the Dispose method"
No. The clients will not be broken, because Dispose(bool) can be
overriden... so I do not see any problems.
Using "Boolean" instead of "bool" will mean that you don't break your clients' code.
If you change the parameter of the method, then it will be broken,
because no client will overload the correct function...
--
Greetings
Jochen
My blog about Win32 and .NET http://blog.kalmbachnet.de/
Dispose(bool) can't be overridden in C++/CLI because the compiler won't let
you have Dispose(bool) in the first place. That's the first issue of the
original poster - the work-around is to use Dispose(Boolean ).
The original posters second issue is that clients' code will be broken - the
clients' override of Dispose(bool) will be broken since they'll have to now
override Dispose(Boolean ), but at least calls to Dispose(bool) won't be
broken.
--
David Anton www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C# to C++ converter & VB to C++ converter
Instant J#: VB to J# converter
"Jochen Kalmbach [MVP]" wrote: Hi David! According to the original post: "If we simply re-compile our code with the new compiler (after syntax changes), it we will break our clients. Clients will have to change their code for overriding the Dispose method"
No. The clients will not be broken, because Dispose(bool) can be overriden... so I do not see any problems.
Using "Boolean" instead of "bool" will mean that you don't break your clients' code.
If you change the parameter of the method, then it will be broken, because no client will overload the correct function...
-- Greetings Jochen
My blog about Win32 and .NET http://blog.kalmbachnet.de/ This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Jazper |
last post by:
hi
i have this problem. i made a class deverted by CRootItem with
implementation of IDisposable-Interface. i made a test-funktion to test my
Dispose-Method.... but when set a breakpoint in my Dispose-Method and call
the GC nothing happend!!! my Disposemethod has never been called!! so the GC
dont call my Dispose-Method although I implemented IDisposable?
what am i doing wrong?
|
by: Hasani \(remove nospam from address\) |
last post by:
I was reading a ppt ( http://www.gotdotnet.com/team/pdc/4064/tls310.ppt )
and came aross this statement.
"Users can leverage a destructor. The C++ compiler generates all the Dispose
code automatically, including chaining calls to Dispose. (There is no
Dispose pattern)"
but Dispose can thrown an exception. Is the exception supressed?
|
by: Val3 |
last post by:
Hi all.
I need to build dll(s) and windows services using VB .NET 2005 Express. When
I make File/New project the windows contain only Windows application,
Windows control library, Console application, DVD collection starter kit.
How can I do? Any suggest?
Thanks in advance.
VAL
|
by: Bob |
last post by:
Hi,
The compiler gives Warning 96 Variable 'cmdSource' is used before it has
been assigned a value. A null reference exception could result at runtime.
Dim cmdSource as SQlClient.SQLDataReader
Try
Set up the database read and do it.
Catch ex as system.exception
exception stuff here
Finally
|
by: Richard Collette |
last post by:
Hi,
I have a service, that runs perfectly when executed outside of the web
service environment. When called as a web service I get the exception
listed below sporadically. A call to the web method may succeed one time and
not another. I cannot find any reason why it would work one time and not
another. The exception occurs every two or three calls to the web method.
The service utilizes a COM component provided by PeopleSoft...
| |
by: evle |
last post by:
haw to read data from an Infrared Infrared Remote Control
|
by: Victory |
last post by:
Hi,
I just used VS2008 and migrated a project from 2005 to
2008. The reason is that MSDN docs is saying the Image
object in .NET Framework 3.5 has a Finalize method, which i
want to try out since my app is processing a few image
files and then saying it is running out of memory. I am
using the Dispose method of this object to get rid of it
and then setting it to Nothing. in any case, when i used VS
2008, intellisense still does not show...
|
by: AWW |
last post by:
XP VB 2005 drawing line graphics in a PictureBox - from a simple
minded former FORTRAN programmer.
The help examples have the graphics drawing code (lines & rectangles)
in the PictureBox paint event handler - making it a static display.
But I don't want a static display - I want to draw dynamic data so how
do I get the data to the event handler - if I need to do that.
I have also done line drawings on the Form but those drawings have an...
|
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...
|
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...
|
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...
| |
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |