我ReadDirectoryChangesW用来监视目录中文件何时更改。我正在使用带有完成例程函数的异步版本(根据文档)。
一切正常,直到我希望停止监视该文件夹。
为了停止监控,我调用了这个Close函数。
问题是我仍然收到最后一个通知,但到那时我已经破坏了我的LPOVERLAPPED价值。
如何停止ReadDirectoryChangesW并阻止MyCompletionRoutine调用我的函数。
// get the handle    
_handle = CreateFileW( ... )
void Read()
{
  ...
  ReadDirectoryChangesW( _handle, ..., &MyCompletionRoutine );
  ...
}
void Close()
{
  ::CancelIo(_handle );           
  ::CloseHandle(_handle );
}
void __stdcall MyCompletionRoutine (
    const unsigned long dwErrorCode,
    const unsigned long dwNumberOfBytesTransfered,
    _OVERLAPPED* lpOverlapped )
{
  // ... do stuff and start a read again
  Read();
}
在上面的代码中,我可能已经调用Read但我想在MyCompletionRoutine调用之前停止。
不知道这是否有帮助,但我得到的错误信息是317