问题是这个异常在什么情况下会产生?请编码说明

解决方案 »

  1.   

    int PASCAL CFileException::OsErrorToException(LONG lOsErr)BOOL CFile::Open(LPCTSTR lpszFileName, UINT nOpenFlags,
    CFileException* pException)
    AfxThrowFileException(CFileException::OsErrorToException(lOsError),void AFXAPI _AfxFillOleFileException(CFileException* pError, SCODE sc)
    n多
      你最好自己去看 mfc 它的原代码,,,
      

  2.   

    LPCTSTR    pszPath  = _T("C:/ntldr");
      try
      {
        CFile fileA(pszPath, CFile::modeRead+CFile::shareDenyNone);
        CFile fileB(pszPath, CFile::modeRead+CFile::shareDenyNone);    fileA.LockRange (0, 1);
        fileB.LockRange (0, 1);//<= throwed here.     fileA.Close ();
        fileB.Close ();
      }
      catch (CFileException *e)
      {             
        if (CFileException::lockViolation  ==  e->m_cause)
    {
          ::AfxMessageBox (_T("i've got it."), MB_OK, 0);
          e->Delete();
          return ;
    }
        e->Delete();
      }  ::AfxMessageBox (_T("--=* THE END *=--"), MB_OK, 0);
      return ;
      

  3.   

    你应该以共享方式打开一个文件!也许你多次打开了自己的同一个程序,而这些程序中都要打开一个文件,但打开方式没有选择共享方式!
    CFile theFile
    theFile.Open(pszPath, CFile::modeRead+CFile::shareDenyNone);