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. how to close document handle

how to close document handle

Scheduled Pinned Locked Moved C / C++ / MFC
tutorial
5 Posts 4 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.
  • V Offline
    V Offline
    VCsamir
    wrote on last edited by
    #1

    hi friends, i have have a MDI Application. when i close a document using onclosedocument. my document handle remains active though the members used in document are set to null. so i cannot check this condition if(doc) as it returns true. whereas in the if block it cannot access the members so app crashes eg.

    if(doc) //handle =FAEX000
    {
    doc->getprivatevariable_or_functions(); // the application crashes here
    }

    thanking in anticipation REgards Samir

    C C 2 Replies Last reply
    0
    • V VCsamir

      hi friends, i have have a MDI Application. when i close a document using onclosedocument. my document handle remains active though the members used in document are set to null. so i cannot check this condition if(doc) as it returns true. whereas in the if block it cannot access the members so app crashes eg.

      if(doc) //handle =FAEX000
      {
      doc->getprivatevariable_or_functions(); // the application crashes here
      }

      thanking in anticipation REgards Samir

      C Offline
      C Offline
      Cedric Moonen
      wrote on last edited by
      #2

      How did you allocated the "document" ? I mean how did you create the pointer doc (it seems it is a pointer, right?). When you release your document (for instance by deleting the memory), you also always have to assign null to it, so that you can check whether it has been deallocated. If you do that, then your code will work properly (the if segment won't be entered since doc is NULL).

      Cédric Moonen Software developer
      Charting control [v3.0] OpenGL game tutorial in C++

      1 Reply Last reply
      0
      • V VCsamir

        hi friends, i have have a MDI Application. when i close a document using onclosedocument. my document handle remains active though the members used in document are set to null. so i cannot check this condition if(doc) as it returns true. whereas in the if block it cannot access the members so app crashes eg.

        if(doc) //handle =FAEX000
        {
        doc->getprivatevariable_or_functions(); // the application crashes here
        }

        thanking in anticipation REgards Samir

        C Offline
        C Offline
        CPallini
        wrote on last edited by
        #3

        You may override CDocument::OnCloseDocument for marking your document as invalid (you may set a custom property for the purpose) and then check for document validity before any access. :)

        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
        This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
        [My articles]

        V 1 Reply Last reply
        0
        • C CPallini

          You may override CDocument::OnCloseDocument for marking your document as invalid (you may set a custom property for the purpose) and then check for document validity before any access. :)

          If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
          This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
          [My articles]

          V Offline
          V Offline
          VCsamir
          wrote on last edited by
          #4

          Hi pallini Sir, i have main document which has child documents. so in main document i have overridden the function document:oncloseDocumenet() and called ColeDocument:CloseDocument. Thanks For reply Sir.. but prob still not resolved Regards Samir

          L 1 Reply Last reply
          0
          • V VCsamir

            Hi pallini Sir, i have main document which has child documents. so in main document i have overridden the function document:oncloseDocumenet() and called ColeDocument:CloseDocument. Thanks For reply Sir.. but prob still not resolved Regards Samir

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

            See my answer to your reposted question.

            I must get a clever new signature for 2011.

            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