Click here to Skip to main content
15,887,746 members
Home / Discussions / Managed C++/CLI
   

Managed C++/CLI

 
GeneralRe: Calling into .NET Class Lib from a C++ app Pin
led mike31-Aug-07 4:20
led mike31-Aug-07 4:20 
QuestionC++/CLI Zooming Pin
BuckBrown28-Aug-07 12:45
BuckBrown28-Aug-07 12:45 
AnswerRe: C++/CLI Zooming Pin
Luc Pattyn28-Aug-07 12:49
sitebuilderLuc Pattyn28-Aug-07 12:49 
GeneralRe: C++/CLI Zooming Pin
BuckBrown29-Aug-07 13:02
BuckBrown29-Aug-07 13:02 
GeneralRe: C++/CLI Zooming [modified] Pin
Luc Pattyn29-Aug-07 13:17
sitebuilderLuc Pattyn29-Aug-07 13:17 
GeneralRe: C++/CLI Zooming Pin
Mark Salsbery29-Aug-07 14:18
Mark Salsbery29-Aug-07 14:18 
GeneralRe: C++/CLI Zooming Pin
Luc Pattyn29-Aug-07 15:41
sitebuilderLuc Pattyn29-Aug-07 15:41 
GeneralRe: C++/CLI Zooming Pin
Mark Salsbery29-Aug-07 18:40
Mark Salsbery29-Aug-07 18:40 
Starting in VC++ 2005, you can't call Dispose directly.  You can deterministically clean up a
managed object with delete though.  You can also use stack semantics - like a local variable
with the same scoping but it's created on the managed heap behind the scenes.  It's automatically
disposed when it goes out of scope.

    Matrix^ myMatrix = gcnew Matrix();
    //myMatrix->Dispose();  <font color="Red"><-- can't do this!</font>
    delete myMatrix; <font><font color="Red">// Dispose will be called here</font></font> 
    or

    Matrix myMatrix; <font color="Red">// Dispose will be called when this goes out of scope</font>
    
You also can't make ref classes disposable (derived explicitly from IDisposable) in C++. 

Now, if you add a destructor, the class automagically inherits from IDisposable, the
destructor becomes Dispose(), and an explicit finalizer can be added ( syntax is
"!classname()") which should be called from the destructor.  The compiler makes sure
the finalizer is only called once (SuppressFinalize)...
public ref class TestRef
{
    // example of unmanaged resource
    int *pInts;
public:
    TestRef()
    {
        pInts = new int[100];
    }

    ~TestRef()  // Destructor
    {
        // Release managed resources here...

        // Call finalizer (won't be called a second time by the GC
        //  if the object is explicitly disposed (using delete)
        this->!TestRef();
    }

    !TestRef()  // Finalizer
    {
        // Delete unmanaged resources here
        delete[] pInts;
    }
};
Destructors and Finalizers in Visual C++[^]

Cheers Smile | :)



Mark Salsbery
Microsoft MVP - Visual C++

Java | [Coffee]

GeneralRe: C++/CLI Zooming Pin
Luc Pattyn29-Aug-07 23:31
sitebuilderLuc Pattyn29-Aug-07 23:31 
GeneralRe: C++/CLI Zooming Pin
Mark Salsbery30-Aug-07 4:56
Mark Salsbery30-Aug-07 4:56 
AnswerRe: C++/CLI Zooming Pin
Mark Salsbery28-Aug-07 12:56
Mark Salsbery28-Aug-07 12:56 
QuestionRuberbanding graphics without repainting entire screen Pin
BuckBrown28-Aug-07 10:01
BuckBrown28-Aug-07 10:01 
AnswerRe: Ruberbanding graphics without repainting entire screen Pin
Luc Pattyn28-Aug-07 12:30
sitebuilderLuc Pattyn28-Aug-07 12:30 
GeneralRe: Ruberbanding graphics without repainting entire screen Pin
BuckBrown28-Aug-07 12:43
BuckBrown28-Aug-07 12:43 
QuestionMethod definitions in header files Pin
Xpnctoc28-Aug-07 9:11
Xpnctoc28-Aug-07 9:11 
AnswerRe: Method definitions in header files Pin
led mike29-Aug-07 5:21
led mike29-Aug-07 5:21 
AnswerRe: Method definitions in header files Pin
George L. Jackson29-Aug-07 7:37
George L. Jackson29-Aug-07 7:37 
GeneralRe: Method definitions in header files Pin
Xpnctoc29-Aug-07 8:29
Xpnctoc29-Aug-07 8:29 
GeneralRe: Method definitions in header files [modified] Pin
George L. Jackson29-Aug-07 12:01
George L. Jackson29-Aug-07 12:01 
GeneralRe: Method definitions in header files Pin
Mark Salsbery29-Aug-07 12:33
Mark Salsbery29-Aug-07 12:33 
GeneralRe: Method definitions in header files [modified] Pin
George L. Jackson29-Aug-07 12:54
George L. Jackson29-Aug-07 12:54 
GeneralRe: Method definitions in header files Pin
Mark Salsbery29-Aug-07 13:08
Mark Salsbery29-Aug-07 13:08 
Questionc++ Pin
ellllllllie28-Aug-07 5:03
ellllllllie28-Aug-07 5:03 
AnswerRe: c++ Pin
Luc Pattyn28-Aug-07 5:31
sitebuilderLuc Pattyn28-Aug-07 5:31 
Questionhow to get the primary key for a new row Pin
Stefan Baens27-Aug-07 22:50
Stefan Baens27-Aug-07 22:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.