0

我有一个简单的线程来监视文件的变化。

UINT CFileMonitoringManager::WaitingOnChanges(LPVOID lpParam)
{
    CFileMonitoringManager *pThisClass = (CFileMonitoringManager*)lpParam;

    TCHAR szFileNameBuffer[MAX_PATH];
    DWORD dwBytes = 0;
    DWORD cbOffset = 0;
    CSubscribeTarget *pObject = NULL;
    LPOVERLAPPED lpOverlapped = NULL;    
    FILE_NOTIFY_INFORMATION *pNotifyInfo = NULL;

    while(pThisClass->m_hCompPort)
    {
        if (::GetQueuedCompletionStatus(pThisClass->m_hCompPort, &dwBytes, (LPDWORD)&pObject, &lpOverlapped, INFINITE))
        {
              pNotifyInfo = (PFILE_NOTIFY_INFORMATION)pObject->m_NotifyBuffer;
          DWORD dwBytesRead = 0;
          memset(szFileNameBuffer, 0, sizeof(TCHAR) * MAX_PATH);
          TCHAR* szFileName = 
          GetTCHAR(pNotifyInfo->FileName, pNotifyInfo->FileNameLength, szFileNameBuffer, MAX_PATH);
              //My custom code

          if(!pObject->ReadingDirectory())
              return 0;
        }
    }

    return 0;
}

我正在使用ReadDirectoryChangesWCreateIoCompletionPort。我有这种情况:当我订阅 D:\TESTS\INPUT.txt 并更改 D:\TESTS\INPUT2.txt 我得到正常名称 INPUT.txt 和这些变量中的长度 20

pNotifyInfo->FileName, pNotifyInfo->FileNameLength

我跳过特殊文件的代码并再次开始等待。当我更改 D:\TESTS\INPUT.txt (我订阅的文件)时,我进入 INPUT.txtt 和 18 在这些变量中

pNotifyInfo->FileName, pNotifyInfo->FileNameLength

怎么了?我无法理解。有几次它开始返回正常数据。请帮我

4

0 回答 0