Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. MFC CCmdTarget Assert on App Exit After Calling Windows Form?

MFC CCmdTarget Assert on App Exit After Calling Windows Form?

Scheduled Pinned Locked Moved C / C++ / MFC
csharpc++visual-studiohelpquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    RockyMu
    wrote on last edited by
    #1

    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??

    L 1 Reply Last reply
    0
    • R RockyMu

      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??

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      RockyMu wrote: FormX *f = new FormX(); Where are you deleting f? Artificial intelligence is no match for natural stupidity.

      R 1 Reply Last reply
      0
      • L Lost User

        RockyMu wrote: FormX *f = new FormX(); Where are you deleting f? Artificial intelligence is no match for natural stupidity.

        R Offline
        R Offline
        RockyMu
        wrote on last edited by
        #3

        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

        L 1 Reply Last reply
        0
        • R RockyMu

          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

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups