流程是,我的程序读另外一个程序产生的文件,然后根据这个文件的内容作一些事。
可是现在的问题是,我不知道如何判断这个文件是否被另外的程序处理完毕,我现在只能让我的程序sleep一段时间,这样做实在不是什么好办法,我查了一下相关的函数库,可是实在找不到这方面的资料,请高手帮忙,如何解决不同进程间文件读写的问题。

解决方案 »

  1.   

    比如,我的文件产生一个数据文件abc.cfg,然后交给一个软件,这个软件所作的就是把他复制到c:\根目录,我怎么样才能在这个软件结束复制动作后,读取c:\abc.cfg,而不发生冲突错误。
    一楼老大,能否具体讲讲
    二楼老大,我现在也这么做的,不过觉得有点不是很好,没别的好方法了么
      

  2.   

    读取的时候不发生冲突错误是可以的,关键在CreateFile的dwShareMode里面。HANDLE CreateFile(
      LPCTSTR lpFileName,
      DWORD dwDesiredAccess,
      DWORD dwShareMode,
      LPSECURITY_ATTRIBUTES lpSecurityAttributes,
      DWORD dwCreationDisposition,
      DWORD dwFlagsAndAttributes,
      HANDLE hTemplateFile
    );dwShareMode 
    [in] Sharing mode of the object. You cannot request a sharing mode that conflicts with the access mode specified in a previous open request whose handle is still open.
    If this parameter is zero and CreateFile succeeds, the object cannot be shared and cannot be opened again until the handle is closed. For more information about sharing violations, see the Res section.To enable other processes to share the object while your process has it open, use a combination of one or more of the following values to specify the type of access they can request when they open the object. These sharing options remain in effect until you close the handle to the object.Value Meaning 
    FILE_SHARE_DELETE Enables subsequent open operations on the object to request delete access. Otherwise, other processes cannot open the object if they request delete access. 
    If the object has already been opened with delete access, the sharing mode must include this flag.
    Windows Me/98/95:  This flag is not supported. 
    FILE_SHARE_READ Enables subsequent open operations on the object to request read access. Otherwise, other processes cannot open the object if they request read access. 
    If the object has already been opened with read access, the sharing mode must include this flag.
     
    FILE_SHARE_WRITE Enables subsequent open operations on the object to request write access. Otherwise, other processes cannot open the object if they request write access. 
    If the object has already been opened with write access, the sharing mode must include this flag.
     
      

  3.   

    如果起复制作用的软件是自己编写的可以让其在向C盘复制时,采用把源文件打开获取内容后,再以共享的方式在C盘创建一个新的文件。这时你的程序在读取时至少不会出现打开时的错误。FindFirstChangeNotification可以检测文件发生改变,当检测的目录发生改变后通知程序,程序再去检测数据文件的属性是否正常。正常后就可以进行操作了。
      

  4.   

    进程间通信,应该是好的办法,在操作完后,等消息,如
    opentuxedo(开缝的燕尾服)所说
     
    WaitForSingleObject,
      具体代码WWW.VCKBASE.COM上有
     
      

  5.   

    就是用楼上说得CreateFile里面的dwShareMode 参数。