A problem on loading file using CFile 
Author Message
 A problem on loading file using CFile

I little problem in my program:
In the Document class:
void CMainDoc::Serialize(CArchive& ar)
{
 if (ar.IsStoring())
 {
  // TODO: add storing code here
 }
 else
 {
  // TODO: add loading code here
  MyClass cl;
  cl.Load( ar.GetFile()->GetFilePath() );
 }

Quote:
}

In MyClass:

bool MyClass::Load( CString* fn )
{
   CFileException e;
   CFile fn;
   if (!fn.open( fn, CFile::modeRead, &e ))
   {
#ifdef _DEBUG
    afxDump << "File could not be opened " << e.m_cause << "\n";
#endif
    return false;
    }
    .
    .

Quote:
}

The program can be compiled but it cannot load the file all the time.
The e.m_cause returns 11 and i wonder what's wrong with my program
and how can i solve it?
Thanks
Kelvin Leung


Sun, 26 Aug 2001 03:00:00 GMT  
 A problem on loading file using CFile
  You've got fn declared twice, as the parameter CString, and
as a CFile.

  Dan

Quote:

>I little problem in my program:
>In the Document class:
>void CMainDoc::Serialize(CArchive& ar)
>{
> if (ar.IsStoring())
> {
>  // TODO: add storing code here
> }
> else
> {
>  // TODO: add loading code here
>  MyClass cl;
>  cl.Load( ar.GetFile()->GetFilePath() );
> }
>}

>In MyClass:

>bool MyClass::Load( CString* fn )
>{
>   CFileException e;
>   CFile fn;
>   if (!fn.open( fn, CFile::modeRead, &e ))
>   {
>#ifdef _DEBUG
>    afxDump << "File could not be opened " << e.m_cause << "\n";
>#endif
>    return false;
>    }
>    .
>    .
>}

>The program can be compiled but it cannot load the file all the time.
>The e.m_cause returns 11 and i wonder what's wrong with my program
>and how can i solve it?
>Thanks
>Kelvin Leung



Sun, 26 Aug 2001 03:00:00 GMT  
 A problem on loading file using CFile
As far as I could find out the error 11 is a "sharing" violation.

Have a look at the rest of the CFileExcetion values e there is also a
clear text message you can look at.

Guido

Kelvin Leung schrieb:

Quote:
> I little problem in my program:
> In the Document class:
> void CMainDoc::Serialize(CArchive& ar)
> {
>  if (ar.IsStoring())
>  {
>   // TODO: add storing code here
>  }
>  else
>  {
>   // TODO: add loading code here
>   MyClass cl;
>   cl.Load( ar.GetFile()->GetFilePath() );
>  }
> }

> In MyClass:

> bool MyClass::Load( CString* fn )
> {
>    CFileException e;
>    CFile fn;
>    if (!fn.open( fn, CFile::modeRead, &e ))
>    {
> #ifdef _DEBUG
>     afxDump << "File could not be opened " << e.m_cause << "\n";
> #endif
>     return false;
>     }
>     .
>     .
> }

> The program can be compiled but it cannot load the file all the time.
> The e.m_cause returns 11 and i wonder what's wrong with my program
> and how can i solve it?
> Thanks
> Kelvin Leung



Sun, 26 Aug 2001 03:00:00 GMT  
 A problem on loading file using CFile
The CFile fn and the CString fn is just a typing mistake. In my original
program their names are different.
Quote:

> I little problem in my program:
> In the Document class:
> void CMainDoc::Serialize(CArchive& ar)
> {
>  if (ar.IsStoring())
>  {
>   // TODO: add storing code here
>  }
>  else
>  {
>   // TODO: add loading code here
>   MyClass cl;
>   cl.Load( ar.GetFile()->GetFilePath() );
>  }
> }

> In MyClass:

> bool MyClass::Load( CString* fn )
> {
>    CFileException e;
>    CFile fn;
>    if (!fn.open( fn, CFile::modeRead, &e ))
>    {
> #ifdef _DEBUG
>     afxDump << "File could not be opened " << e.m_cause << "\n";
> #endif
>     return false;
>     }
>     .
>     .
> }

> The program can be compiled but it cannot load the file all the time.
> The e.m_cause returns 11 and i wonder what's wrong with my program
> and how can i solve it?
> Thanks
> Kelvin Leung



Mon, 27 Aug 2001 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. A problem on loading file using CFile

2. problem using CFile::SetStatus to change file time

3. Problem with write using CFile and read using fscanf()

4. Reading from text files using CFile object

5. Reading a File's contents using CFile

6. Reading a File's contents using CFile

7. Reading a File's contents using CFile

8. Opening and closing a file on a Novell network using CFile

9. Q: How to share file(s) using CFile

10. appending to text file using CFile

11. File modification using CFile Object

12. Reading from files using CFile

 

 
Powered by phpBB® Forum Software