MFC CCmdTarget Assert on App Exit After Calling Windows Form?
-
I have a Visual Studio solution that contains an MFC executable project and a .NET C# class library project with a Windows Form. When I instantiate a simple C# Windows form from the MFC program, then, on closing out the form and exiting the MFC app, I receive an assert in the CCmdTarget destructor (line 48 cmdtarg.cpp) because m_dwRef is > 1. I have recreated this with the simplest MFC and C# windows from that I can make. I still get this assert. Other than the assert on close-out, everything else works fine. The form is instantiated from an MFC CDocument class object using the following code: FormX *f = new FormX(); f->ShowDialog(); What's my problem??
-
I have a Visual Studio solution that contains an MFC executable project and a .NET C# class library project with a Windows Form. When I instantiate a simple C# Windows form from the MFC program, then, on closing out the form and exiting the MFC app, I receive an assert in the CCmdTarget destructor (line 48 cmdtarg.cpp) because m_dwRef is > 1. I have recreated this with the simplest MFC and C# windows from that I can make. I still get this assert. Other than the assert on close-out, everything else works fine. The form is instantiated from an MFC CDocument class object using the following code: FormX *f = new FormX(); f->ShowDialog(); What's my problem??
-
RockyMu wrote: FormX *f = new FormX(); Where are you deleting f? Artificial intelligence is no match for natural stupidity.
Thanks, Anon. I was not deleting 'f' thinking that it would just get garbage-collected, but I can see the problem with that. Since deleting 'f' requires a destructor, I have added the 'delete f;' code to the MFC object and a destructor '~FormX(){}' to the form's code. When I compile the MFC code, I get an C3841 error on the delete statement which says "C3841: illegal delete expression: managed type 'ClassLibrary1::FormX' does not have a destructor defined." I am still missing something? Paul
-
Thanks, Anon. I was not deleting 'f' thinking that it would just get garbage-collected, but I can see the problem with that. Since deleting 'f' requires a destructor, I have added the 'delete f;' code to the MFC object and a destructor '~FormX(){}' to the form's code. When I compile the MFC code, I get an C3841 error on the delete statement which says "C3841: illegal delete expression: managed type 'ClassLibrary1::FormX' does not have a destructor defined." I am still missing something? Paul
RockyMu wrote: I am still missing something? Sorry man.... can't help you there. MFC->.NET interaction I haven't delved into. No garbage collection in MFC to help you out with the new/delete operations. But I imagine that your problem is a result of your instantiation of the FormX object and MFC not knowing how to release it properly. At least it's a place for you to start looking. :) Artificial intelligence is no match for natural stupidity.