HANDLE handle;
if((handle=CreateFile(filepath,GENERIC_WRITE|GENERIC_READ,0,NULL,
     OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL))==INVALID_HANDLE_VALUE)
{
if((handle=CreateFile(filepath,GENERIC_WRITE|GENERIC_READ, NULL, NULL,
          CREATE_NEW,FILE_ATTRIBUTE_NORMAL,NULL))==INVALID_HANDLE_VALUE)
return false;
}
我做的是下载文件的功能
下载完文件 把下载的删掉 重新再下 有的时候就会出现 ”存取 一未命名文件 时发生共享违例“
创建文件代码就是那样子的  大家帮我看下为什么会出现这个情况  
感谢ing

解决方案 »

  1.   

    是多线程。可是原来都不会出现这个情况
    我下载文件是用映射内存来做的
     HANDLE handle;
        if((handle=CreateFile(filepath,GENERIC_WRITE|GENERIC_READ,0,NULL,
                OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL))==INVALID_HANDLE_VALUE)
        {
            if((handle=CreateFile(filepath,GENERIC_WRITE|GENERIC_READ, NULL, NULL,
                     CREATE_NEW,FILE_ATTRIBUTE_NORMAL,NULL))==INVALID_HANDLE_VALUE)
                    return false;
        }
    看下跟这段代码有没有关系呀
    晕晕的
      

  2.   

    在debug中找到这个
    CFile exception: sharingViolation, File Unknown, OS error information = 32.
    想找到这个根源怎么找呢?
      

  3.   

    没啥关系,不过这段代码的意思很傻应该可以合并一个,应该是这个意思!OPEN_ALWAYSOpens the file, if it exists. If the file does not exist, the function creates the file as if dwCreationDisposition were CREATE_NEW.
      

  4.   

    CFile exception: sharingViolation, File Unknown, OS error information = 32.
    First-chance exception in testFileClient.exe (KERNEL32.DLL): 0xE06D7363: Microsoft C++ Exception.
    Warning: Uncaught exception in WindowProc (returning 1).怎么找才能找到问题的根源呢? 高手帮忙下呀