Microsoft Foundation Classes (mfc.hlp) (Table of Contents; Topic list)
CFile::Open
CFile                                       Up Contents Index Back
──Microsoft Foundation Classes──────────────────────────────────────────────
 
  virtual BOOL Open( const char* pszFileName, UINT nOpenFlags,
                     CFileException* pError = NULL );
 
  Parameter     Description
 
  <pszFileName> A string that is the path to the desired file. The path
                may be relative or absolute, but may not contain a network
                name.
 
  <nOpenFlags>  A UINT that defines the file's sharing and access mode. It
                specifies the action to take when opening the file. You
                can combine options by using the bitwise-OR (|) operator.
                One access permission and one share option are required;
                the modeCreate and modeNoInherit modes are optional. See
                the CFile constructor for a list of mode options.
 
  <pError>      A pointer to an existing file-exception object that
                indicates the completion status of the open operation.
 
  Remarks
 
  Open is designed for use with the default CFile constructor. The two
  functions form a "safe" method for opening a file where a failure is a
  normal, expected condition. The constructor is guaranteed to succeed,
  and Open returns (a pointer to) an exception object, bypassing the
  THROW/TRY/CATCH mechanism.
 
  Return Value
 
  TRUE if the open was successful; otherwise FALSE. The <pError> parameter
  is only meaningful if FALSE is returned.
 
  Example
 
  CFile f;
  CFileException e;
  char* pFileName = "test.dat";
  if( !f.Open( pFileName, CFile::modeCreate | CFile::modeWrite, &e ) )
     {
        #ifdef _DEBUG
           afxDump << "File could not be opened " << e.m_cause << "\n";
        #endif
     }
 
 
  See Also
 
  CFile::CFile, CFile::Close
 
 
                                     -♦-