我希望在提供I / O完成例程的asynchronous模式下使用函数ReadDirectoryChangesW() 。
问题是我不知道如何检索完成例程( CALLBACK函数)中有关更改的确切信息。 完成程序定义如下:
VOID CALLBACK FileIOCompletionRoutine( [in] DWORD dwErrorCode,[in] DWORD dwNumberOfBytesTransfered,[in] LPOVERLAPPED lpOverlapped );
我不知道信息包含在LPOVERLAPPED结构中。 但我不知道如何得到它。
如何用pthreads在平台上进行asynchronous的线程间通信
如何将WinRTasynchronous任务集成到现有的同步库中?
高效的Linux套接字(DMA /零拷贝)
什么是将C ++ 11asynchronous/期货与WindowsasynchronousIO结合起来的最佳API?
与Windows命名pipe道(.Net)的asynchronous双向通信
在Windows UAP应用程序中如何解决“'IAsyncActionWithProgress <>'在未引用的程序集中定义”
你如何将主机名asynchronousparsing为IP地址?
线程安全和asynchronous信号安全的区别
以asynchronous模式读取Linux串口
很好的问题! 这已经晚了7年,但是这里有一些答案,或者更重要的是, 如何找到答案。 所以,ReadDirectoryChangesW的文档:
https://msdn.microsoft.com/en-us/library/windows/desktop/aa365465%28v=vs.85%29.aspx
在参数部分给出一个到FileIOCompletionRoutine的链接:
https://msdn.microsoft.com/en-us/library/windows/desktop/aa364052%28v=vs.85%29.aspx
在“示例”部分给出了使用完成例程的命名管道服务器的链接:
https://msdn.microsoft.com/en-us/library/windows/desktop/aa365601%28v=vs.85%29.aspx
它相信或者不相信甚至不使用ReadDirectoryChangesW,但实际上给出了一个使用ReadFileEx的例子,它也使用FileIOCompletionRoutine:
https://msdn.microsoft.com/en-us/library/windows/desktop/aa365468%28v=vs.85%29.aspx
你可以在这段代码中看到使用这两个函数(ReadFileEx和CompletedReadRoutine(这是应用程序定义的回调函数FileIOCompletionRoutine的实现))的例子:
// CompletedWriteRoutine(DWORD,DWORD,LPOVERLAPPED) // This routine is called as a completion routine after writing to // the pipe,or when a new client has connected to a pipe instance. // It starts another read operation. VOID WINAPI CompletedWriteRoutine(DWORD dwErr,DWORD cbWritten,LPOVERLAPPED lpOverLap) { LPPIPEINST lpPipeInst; BOOL fRead = FALSE; // lpOverlap points to storage for this instance. lpPipeInst = (LPPIPEINST) lpOverLap; // The write operation has finished,so read the next request (if // there is no error). if ((dwErr == 0) && (cbWritten == lpPipeInst->cbToWrite)) fRead = ReadFileEx( lpPipeInst->hPipeInst,lpPipeInst->chRequest,BUFSIZE*sizeof(TCHAR),(LPOVERLAPPED) lpPipeInst,(LPOVERLAPPED_COMPLETION_ROUTINE) CompletedReadRoutine); // disconnect if an error occurred. if (! fRead) disconnectAndClose(lpPipeInst); } // CompletedReadRoutine(DWORD,LPOVERLAPPED) // This routine is called as an I/O completion routine after reading // a request from the client. It gets data and writes it to the pipe. VOID WINAPI CompletedReadRoutine(DWORD dwErr,DWORD cbBytesRead,LPOVERLAPPED lpOverLap) { LPPIPEINST lpPipeInst; BOOL fWrite = FALSE; // lpOverlap points to storage for this instance. lpPipeInst = (LPPIPEINST) lpOverLap; // The read operation has finished,so write a response (if no // error occurred). if ((dwErr == 0) && (cbBytesRead != 0)) { GetAnswerToRequest(lpPipeInst); fWrite = WriteFileEx( lpPipeInst->hPipeInst,lpPipeInst->chReply,lpPipeInst->cbToWrite,(LPOVERLAPPED_COMPLETION_ROUTINE) CompletedWriteRoutine); } // disconnect if an error occurred. if (! fWrite) disconnectAndClose(lpPipeInst); }
这不是一个很好的答案(我只是在探讨是否我甚至想要使用这些功能),但它应该帮助人们开始。
也可以看看:
https://msdn.microsoft.com/en-us/library/windows/desktop/aa365261%28v=vs.85%29.aspx
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。