最近在做播放器,遇到一个麻烦的问题。
用播放器打开一个音乐文件,比如A.mp3,此时这个文件被占用。
然后再用我的播放器打开列表,因为列表要一个一个读取文件信息,
读取到这个文件时,就会出现错误提示框。
说是找不到A.mp3,调试的时候,会发现
file.Seek(-128,CFile::end);
这里出错了,用try{}catch(CFileException *e){;}
也无效,还是弹出错误提示框,列表后面的文件也不会被读取,被中断了。
请问怎么处理。分不多,还请高手救命。

解决方案 »

  1.   

    try
    {
     CFile file(_T("xxx.mp3"), CFile::modeRead);
     ...
     file.Close();
    }
    catch(...)
    {
     ...
    }
      

  2.   

    其实我就这样写的,语法上应该不是问题:CFile file;
    try{
    file.Open((LPCTSTR)path,CFile::modeRead);
    long seekpos=128;
    file.Seek(-seekpos,CFile::end);
    file.Close();
    }catch(CFileException *e){;};不过他总是在file.Seek(-seekpos,CFile::end);里出错,try{}catch{}没用。
      

  3.   

    在ULONGLONG CFile::Seek(LONGLONG lOff, UINT nFrom)
    {
    ASSERT_VALID(this);
    ASSERT(m_hFile != INVALID_HANDLE_VALUE);
    ASSERT(nFrom == begin || nFrom == end || nFrom == current);
    ASSERT(begin == FILE_BEGIN && end == FILE_END && current == FILE_CURRENT);ASSERT(m_hFile != INVALID_HANDLE_VALUE);这里出错,
    我不想让他提示,继续执行不行么?
      

  4.   

    file.Open((LPCTSTR)path,CFile::modeRead);
    -->
    CFile file((LPCTSTR)path,CFile::modeRead);
      

  5.   

    While the CFile constructor will throw an exception in an error condition, Open will return FALSE for error conditions. Open can still initialize a CFileException object to describe the error, however. If you don't supply the pError parameter, or if you pass NULL for pError, Open will return FALSE and not throw a CFileException. If you pass a pointer to an existing CFileException, and Open encounters an error, the function will fill it with information describing that error. In neither case will Open throw an exception. 看这个