Click to See Complete Forum and Search --> : How to read the file


olivier cheneson
October 19th, 1999, 06:48 AM
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);

}

mdangers
October 19th, 1999, 07:27 AM
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.