Thread: Fopen returns a cause code 2 but the file exists in the directory.

  1. #1
    Registered User
    Join Date
    Dec 2007

    Fopen returns a cause code 2 but the file exists in the directory.

    I get the fact that the cause code value of 2 is for the file not found.

    All I do is just read the file and open to see if its readable.

    I am pasting below a piece of code.
    BOOL bReadFile( BYTE* p, INT32& nSize, CString strFilename)
    	CFile			cfSessionFile;
    	CFileException	ex;
    	if (cfSessionFile.Open( strFilename, CFile::modeRead, &ex))
    		nSize = (INT32) cfSessionFile.GetLength();
    		if((p != NULL) && (nSize > 0))
    			cfSessionFile.Read( p, nSize);
                           {  m_ologging.writelogmessage("failed to open the file with cause =%d",ex.m_cause);
    		return FALSE;
    	return TRUE;
    I am not sure why should the open fail when we try to open just the file in the read only mode. The application is a multi threading environment. I have run out of ideas as the file does exist, i am tryong to open the gzip files. This does not happen always that the read of this fails.

    I would be really happy if i could get any help on it.


  2. #2
    and the hat of sweating
    Join Date
    Aug 2007
    Toronto, ON
    Print or look at the value of strFilename in the debugger and see if the filename looks correct.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  2. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM
  3. Batch file programming
    By year2038bug in forum Tech Board
    Replies: 10
    Last Post: 09-05-2005, 03:30 PM
  4. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 04:10 PM
Website Security Test