CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 1999
    Posts
    370

    How to read the file

    Hi,

    I have an ini file and i would like to read it but
    it keeps sending the message Access to an unamed file was denied.
    Here is my code.
    Can you check it please ?
    thanks
    Olivier



    //////////////////////////////////////////////////////////////////
    //Open the Ini file and read it
    CString CMyAppApp::GetPathToReport(CString szPathToIni)
    {
    CString szPathToReport = "";

    TRY
    {
    CFile file(szPathToIni, CFile::modeNoTruncate | CFile::modeCreate | CFile::modeWrite);
    DWORD dwLength = file.GetLength();
    LONG lOffset = dwLength, lActual;
    lActual = file.Seek(lOffset, CFile::begin);
    file.Read(&szPathToReport, (UINT) dwLength);

    return(szPathToReport);
    file.Close();

    }
    CATCH_ALL(err)
    {
    err->ReportError();
    }
    END_CATCH_ALL

    return(szPathToReport);

    }


  2. #2
    Join Date
    Oct 1999
    Location
    Germany
    Posts
    238

    Re: How to read the file

    Hi !

    I'm not sure if there are other mistakes, but you
    are definitly using the wrong flags to open
    your file in the CFile-Constructor.
    For ReadOnly-Fileaccess you don't need the
    CFile::modeNoTruncate, CFile::modeCreate, CFile::modeWrite -Flags.
    You should use CFile::modeRead instead.

    regards,

    Matthias.



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured