有这样一段代码 char sRead[4];
CFile mFile(_T("3.wav"),CFile::modeRead);
mFile.Read(sRead,4*sizeof(char));
mFile.Close();为什么运行的时候会出现"在读取3.wav时发生共享违例"的错误呢
已确定运行时没有其他程序在使用这个文件

解决方案 »

  1.   

    那你换一种写法,看看有什么异常出现
    char sRead[4];
    CFile mFile;
    CFileException ex;
    if (!mFileOpen((_T("3.wav"),CFile::modeRead| CFile::shareDenyWrite, &ex))
    {
    // complain if an error happened
          // no need to delete the ex object      TCHAR szError[1024];
          ex.GetErrorMessage(szError, 1024);
          cout << "Couldn't open source file: ";
          cout << szError;
          return 1;}
    mFile.Read(sRead,4*sizeof(char));
    mFile.Close();
      

  2.   

    问题解决了,结贴,感谢 koko1998(追印)