2008-12-05 22 views
11

I/O tamamlanma rutini sağlandığında,işlevini eşzamansız modda kullanmak istiyorum.Tamamlama rutini ile ReadDirectoryChangesW() yöntemi nasıl kullanılır?

Sorun, tamamlanma yordamındaki değişiklik hakkında tam bilgileri nasıl alacağımı bilmiyorum (CALLBACK işlevi). Tamamlama rutin böyle tanımlanır:

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

Ben bilgiler LPOVERLAPPED yapı içerisine dahil ediyorum. Ama nasıl anlayacağımı bilmiyorum.

cevap

3

Mükemmel soru! 7 yıl gecikti, ama işte bir cevap, ya da daha önemlisi, onu nasıl bulabilirim. Yani, ReadDirectoryChangesW için belgeleri: Parametreler bölümünde

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

FileIOCompletionRoutine bir bağlantı veriyor: Örnekler bölümünde Tamamlama rutinleri kullanarak adlandırılmış yöneltme sunucusuna bir bağlantı verilir

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

:

( ) (ReadFileEx Bu iki işlevleri kullanarak bunlardan bir örnek görebilirsiniz

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

ve: inanın

veya hatta ReadDirectoryChangesW kullanmak ama aslında da FileIOCompletionRoutine kullanan ReadFileEx kullanılarak bir örnek verir vermez ve bu kod parçasında) (uygulama tanımlı geri çağırma işlevi FileIOCompletionRoutine bir uygulamasıdır) CompletedReadRoutine:

// 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); 
} 

Bu büyük bir cevap değil (sadece olmadığını keşfetmek oldu Hatta bu işlevleri kullanmak istedim), ama insanların işe başlamasına yardımcı olmalı.

Ayrıca bakınız:

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

İlgili konular