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. CArchive::Close()

CArchive::Close()

Scheduled Pinned Locked Moved C / C++ / MFC
question
15 Posts 6 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.
  • K Kiran Pinjala

    i have my code like this CArchive ar (&fp, CArchive::store); Serialize(ar); ar.Close(); if ar.Close() is called does it close the file pointer associcated with it(fp.Close)? When i am calling copy or delete fn.s after these line on that file, they return unsuccess. What could be the reason. Thank u.

    KIRAN PINJARLA

    P Offline
    P Offline
    prasad_som
    wrote on last edited by
    #2

    kiran.pinjarla wrote:

    if ar.Close() is called does it close the file pointer associcated with it(fp.Close)?

    Yes, it does close CArchive. But not the CFile associated with it.

    kiran.pinjarla wrote:

    When i am calling copy or delete fn.s after these line on that file

    What are these function ? of which class? -- modified at 3:33 Thursday 30th November, 2006 -- modified at 4:59 Thursday 30th November, 2006

    Prasad Notifier using ATL | Operator new[],delete[][^]

    V 1 Reply Last reply
    0
    • K Kiran Pinjala

      i have my code like this CArchive ar (&fp, CArchive::store); Serialize(ar); ar.Close(); if ar.Close() is called does it close the file pointer associcated with it(fp.Close)? When i am calling copy or delete fn.s after these line on that file, they return unsuccess. What could be the reason. Thank u.

      KIRAN PINJARLA

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

      from MSDN:

      CArchive::Close
      void Close( );
      throw( CArchiveException, CFileException );

      Remarks

      Flushes any data remaining in the buffer, closes the archive, and disconnects the archive from the file. No further operations on the archive are permitted. After you close an archive, you can create another archive for the same file or you can close the file.

      The member function Close ensures that all data is transferred from the archive to the file, and it makes the archive unavailable. To complete the transfer from the file to the storage medium, you must first use CFile::Close and then destroy the CFile object.

      i.e. CArchive::Close does NOT close the related CFile. perhaps your is not a CFile, but MSDN also states:

      CFile( int hFile );
      [...]
      The constructor with one argument creates a CFile object that corresponds to an existing operating-system file identified by hFile. No check is made on the access mode or file type. When the CFile object is destroyed, the operating-system file will not be closed. You must close the file yourself.

      kiran.pinjarla wrote:

      When i am calling copy or delete fn.s after these line on that file, they return unsuccess

      what are you doing? :confused: hope that helps...

      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.

      In testa che avete, signor di Ceprano?

      K T 2 Replies Last reply
      0
      • CPalliniC CPallini

        from MSDN:

        CArchive::Close
        void Close( );
        throw( CArchiveException, CFileException );

        Remarks

        Flushes any data remaining in the buffer, closes the archive, and disconnects the archive from the file. No further operations on the archive are permitted. After you close an archive, you can create another archive for the same file or you can close the file.

        The member function Close ensures that all data is transferred from the archive to the file, and it makes the archive unavailable. To complete the transfer from the file to the storage medium, you must first use CFile::Close and then destroy the CFile object.

        i.e. CArchive::Close does NOT close the related CFile. perhaps your is not a CFile, but MSDN also states:

        CFile( int hFile );
        [...]
        The constructor with one argument creates a CFile object that corresponds to an existing operating-system file identified by hFile. No check is made on the access mode or file type. When the CFile object is destroyed, the operating-system file will not be closed. You must close the file yourself.

        kiran.pinjarla wrote:

        When i am calling copy or delete fn.s after these line on that file, they return unsuccess

        what are you doing? :confused: hope that helps...

        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.

        K Offline
        K Offline
        Kiran Pinjala
        wrote on last edited by
        #4

        Thank you capallini. But if i call fp.Close() after ar.Close() i am getting an expection.

        KIRAN PINJARLA

        P CPalliniC 2 Replies Last reply
        0
        • CPalliniC CPallini

          from MSDN:

          CArchive::Close
          void Close( );
          throw( CArchiveException, CFileException );

          Remarks

          Flushes any data remaining in the buffer, closes the archive, and disconnects the archive from the file. No further operations on the archive are permitted. After you close an archive, you can create another archive for the same file or you can close the file.

          The member function Close ensures that all data is transferred from the archive to the file, and it makes the archive unavailable. To complete the transfer from the file to the storage medium, you must first use CFile::Close and then destroy the CFile object.

          i.e. CArchive::Close does NOT close the related CFile. perhaps your is not a CFile, but MSDN also states:

          CFile( int hFile );
          [...]
          The constructor with one argument creates a CFile object that corresponds to an existing operating-system file identified by hFile. No check is made on the access mode or file type. When the CFile object is destroyed, the operating-system file will not be closed. You must close the file yourself.

          kiran.pinjarla wrote:

          When i am calling copy or delete fn.s after these line on that file, they return unsuccess

          what are you doing? :confused: hope that helps...

          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.

          T Offline
          T Offline
          toxcct
          wrote on last edited by
          #5

          dear, <pre></pre> tags are for posting code samples, not quotation, because you're breaking the page... thank you ;)


          You don't know where to start ? ask a good friend

          [VisualCalc 3.0][Flags Beginner's Guide]

          CPalliniC 1 Reply Last reply
          0
          • K Kiran Pinjala

            Thank you capallini. But if i call fp.Close() after ar.Close() i am getting an expection.

            KIRAN PINJARLA

            P Offline
            P Offline
            prasad_som
            wrote on last edited by
            #6

            You need to call CFile::Close before CArchive::Close.

            Prasad Notifier using ATL | Operator new[],delete[][^]

            N 1 Reply Last reply
            0
            • P prasad_som

              You need to call CFile::Close before CArchive::Close.

              Prasad Notifier using ATL | Operator new[],delete[][^]

              N Offline
              N Offline
              Nibu babu thomas
              wrote on last edited by
              #7

              prasad_som wrote:

              You need to call CFile::Close before CArchive::Close.

              You are wrong. CArchive does not close the file object. This is the source code...

              void CArchive::Close()
              {
              ASSERT_VALID(m_pFile);

              Flush();
              m\_pFile = NULL; // --> Just detaches the file pointer that's all, but doesn't close
              

              }


              Nibu thomas A Developer Programming tips[^]  My site[^]

              P 1 Reply Last reply
              0
              • N Nibu babu thomas

                prasad_som wrote:

                You need to call CFile::Close before CArchive::Close.

                You are wrong. CArchive does not close the file object. This is the source code...

                void CArchive::Close()
                {
                ASSERT_VALID(m_pFile);

                Flush();
                m\_pFile = NULL; // --> Just detaches the file pointer that's all, but doesn't close
                

                }


                Nibu thomas A Developer Programming tips[^]  My site[^]

                P Offline
                P Offline
                prasad_som
                wrote on last edited by
                #8

                I think you replying to my previous reply. Haven't you seen I've already modified it?

                Prasad Notifier using ATL | Operator new[],delete[][^]

                N 1 Reply Last reply
                0
                • K Kiran Pinjala

                  Thank you capallini. But if i call fp.Close() after ar.Close() i am getting an expection.

                  KIRAN PINJARLA

                  CPalliniC Offline
                  CPalliniC Offline
                  CPallini
                  wrote on last edited by
                  #9

                  Since the following snipped of code works fine on my system:

                      CFile file;
                  MyObject obj;
                  file.Open("foo.txt",CFile::modeWrite|CFile::modeCreate);
                  CArchive ar(&file, CArchive::store);
                  obj.Serialize(ar);
                  ar.Close();
                  file.Close();
                  

                  hope that helps. :confused:

                  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.

                  In testa che avete, signor di Ceprano?

                  K 1 Reply Last reply
                  0
                  • P prasad_som

                    I think you replying to my previous reply. Haven't you seen I've already modified it?

                    Prasad Notifier using ATL | Operator new[],delete[][^]

                    N Offline
                    N Offline
                    Nibu babu thomas
                    wrote on last edited by
                    #10

                    prasad_som wrote:

                    I think you replying to my previous reply. Haven't you seen I've already modified it?

                    No I didn't see but still why are you saying that CFile::Close should be called before CArchive:Close. Why what's the reason?


                    Nibu thomas A Developer Programming tips[^]  My site[^]

                    P 1 Reply Last reply
                    0
                    • N Nibu babu thomas

                      prasad_som wrote:

                      I think you replying to my previous reply. Haven't you seen I've already modified it?

                      No I didn't see but still why are you saying that CFile::Close should be called before CArchive:Close. Why what's the reason?


                      Nibu thomas A Developer Programming tips[^]  My site[^]

                      P Offline
                      P Offline
                      prasad_som
                      wrote on last edited by
                      #11

                      :doh: You are right.

                      Prasad Notifier using ATL | Operator new[],delete[][^]

                      1 Reply Last reply
                      0
                      • CPalliniC CPallini

                        Since the following snipped of code works fine on my system:

                            CFile file;
                        MyObject obj;
                        file.Open("foo.txt",CFile::modeWrite|CFile::modeCreate);
                        CArchive ar(&file, CArchive::store);
                        obj.Serialize(ar);
                        ar.Close();
                        file.Close();
                        

                        hope that helps. :confused:

                        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.

                        K Offline
                        K Offline
                        Kiran Pinjala
                        wrote on last edited by
                        #12

                        Yes. I was wrong. It was not this fp.Close() which was causing the exception. It was another Close(). Anyhow learned a few new things. Thank you all.

                        KIRAN PINJARLA

                        1 Reply Last reply
                        0
                        • P prasad_som

                          kiran.pinjarla wrote:

                          if ar.Close() is called does it close the file pointer associcated with it(fp.Close)?

                          Yes, it does close CArchive. But not the CFile associated with it.

                          kiran.pinjarla wrote:

                          When i am calling copy or delete fn.s after these line on that file

                          What are these function ? of which class? -- modified at 3:33 Thursday 30th November, 2006 -- modified at 4:59 Thursday 30th November, 2006

                          Prasad Notifier using ATL | Operator new[],delete[][^]

                          V Offline
                          V Offline
                          Viorel
                          wrote on last edited by
                          #13

                          prasad_som wrote:

                          You need to call CFile::Close before using CArchive::Close

                          In my opinion the file must be closed after closing the archive. Otherwise it will be impossible to flush the last data kept in an internal buffer of CArchive. If the CFile and CArchive objects are created on the stack, then they will be closed automatically in right order.

                          P 1 Reply Last reply
                          0
                          • V Viorel

                            prasad_som wrote:

                            You need to call CFile::Close before using CArchive::Close

                            In my opinion the file must be closed after closing the archive. Otherwise it will be impossible to flush the last data kept in an internal buffer of CArchive. If the CFile and CArchive objects are created on the stack, then they will be closed automatically in right order.

                            P Offline
                            P Offline
                            prasad_som
                            wrote on last edited by
                            #14

                            Viorel. wrote:

                            In my opinion the file must be closed after closing the archive

                            You are right.

                            Prasad Notifier using ATL | Operator new[],delete[][^]

                            1 Reply Last reply
                            0
                            • T toxcct

                              dear, <pre></pre> tags are for posting code samples, not quotation, because you're breaking the page... thank you ;)


                              You don't know where to start ? ask a good friend

                              [VisualCalc 3.0][Flags Beginner's Guide]

                              CPalliniC Offline
                              CPalliniC Offline
                              CPallini
                              wrote on last edited by
                              #15

                              OK, dear... :):-D:) but what does it mean because you're breaking the page...? I cannot understand :confused:, please explain to me. :)

                              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.

                              In testa che avete, signor di Ceprano?

                              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