"An attempt was made to access an unnamed file past its end "


  • Hi all,

     When i tried load from the archive file ,i am getting the error like "An attempt made to access an unnamed file past its end".How to solve this problem?.
           please suggest a solution.

    this is my code sinnipets:


     CFile f1;

        CArchive ar1(&f1, CArchive::load);
     ar1 >> m_text4 >>m_text5 >> m_text6 >> m_text7 >> m_text8 >> m_text9 >> m_text10 >> m_text11;

    Tuesday, February 09, 2010 11:54 AM


  • The problem is the archive file you have does not have all of the values that you are trying to read.  Maybe you added or changed a parameter since the archive file was saved.  What you can do is to put a TRY-CATCH with a CArchiveException around the ar >> m_text4... line to catch the exception and recover.

    If you have different versions of the data that you store, a good practice would be to add a DWORD at the beginning of your archive file that tells the version of the data file.  Anytime you change the data in the archive file, then increment the version number and load the archive file accordingly.  So for example:

    CArchive ar1(&f1, CArchive::load);
    DWORD version;
      ar1 >> version;
      ar1 >> m_text4 >>m_text5 >> m_text6 >> m_text7;
      if (version > 1)
        ar1 >> m_text8 >> m_text9 >> m_text10;
    CATCH(CArchiveException, ex)
       // Assign default values or something

    • Marked as answer by Nancy Shao Tuesday, February 16, 2010 7:33 AM
    Tuesday, February 09, 2010 4:47 PM