2008-12-05 12 views
11

मैं फ़ंक्शन ReadDirectoryChangesW() का उपयोग एसिंक्रोनस मोड में I/O समापन दिनचर्या के साथ करना चाहता हूं।पूर्ण करने के साथ ReadDirectoryChangesW() विधि का उपयोग कैसे करें?

सवाल यह है कि मुझे नहीं पता कि पूर्णता दिनचर्या में परिवर्तन के बारे में सटीक जानकारी कैसे प्राप्त करें (CALLBACK फ़ंक्शन)। समापन दिनचर्या इस तरह परिभाषित किया गया है:

VOID CALLBACK FileIOCompletionRoutine(
    [in]     DWORD dwErrorCode, 
    [in]     DWORD dwNumberOfBytesTransfered, 
    [in]     LPOVERLAPPED lpOverlapped 
); 

मुझे आश्चर्य है कि जानकारी LPOVERLAPPED संरचना में शामिल है। लेकिन मुझे नहीं पता कि इसे कैसे प्राप्त किया जाए।

उत्तर

3

उत्कृष्ट सवाल! यह 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

ReadFileEx

https://msdn.microsoft.com/en-us/library/windows/desktop/aa365468%28v=vs.85%29.aspx

और आप उनमें से एक उदाहरण के इन दोनों कार्यों का उपयोग कर देख सकते हैं (:

जो मानो या न मानो भी ReadDirectoryChangesW उपयोग नहीं करता है, लेकिन वास्तव में एक उदाहरण ReadFileEx, जो भी FileIOCompletionRoutine का उपयोग करता है का उपयोग कर देता है और 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, 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) lpPipeInst, 
     (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

संबंधित मुद्दे