title: losing files when using ReadDirectoryChangesW
body: <p>I'm using ReadDirectoryChangesW to monitor a directory.<br>
  Here's my simple code  </p>
  
  <pre><code> #include &lt;windows.h&gt;
          #include &lt;stdlib.h&gt;
          #include &lt;stdio.h&gt;
          #include &lt;tchar.h&gt;
          #include &lt;iostream&gt;
          #include &lt;string&gt;
          #include &lt;cwctype&gt;
  
          using namespace std;
          wstring getname(FILE_NOTIFY_INFORMATION *tmp)
          {
              wstring s = L"";
              for (int i = 0;i &lt; tmp-&gt;FileNameLength / 2;i++)
                  s += tmp-&gt;FileName[i];
              return s;
          }
          void _tmain(int argc, TCHAR *argv[])
          {
  
              HANDLE hDir; 
              char notify[1024]; 
              DWORD cbBytes,i; 
              char AnsiChar[3]; 
              wchar_t UnicodeChar[2]; 
              LPTSTR path;
  
              FILE_NOTIFY_INFORMATION *pnotify=(FILE_NOTIFY_INFORMATION *)notify; 
              FILE_NOTIFY_INFORMATION *tmp ; 
  
          //    GetCurrentDirectory(MAX_PATH,path.GetBuffer(MAX_PATH+1));
              wcout.imbue(locale("chs"));
              path = argv[1];
              hDir = CreateFile( path, FILE_LIST_DIRECTORY,
                  FILE_SHARE_READ | 
                  FILE_SHARE_WRITE | 
                  FILE_SHARE_DELETE, NULL, 
                  OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | 
                  FILE_FLAG_OVERLAPPED, NULL); 
              wcout &lt;&lt; L"===CreateFile complete===" &lt;&lt; endl;
              if (hDir == INVALID_HANDLE_VALUE) 
              { 
                  wcout &lt;&lt; L"invalid handle value" &lt;&lt; endl;       
                  return;
              } 
              FILE_NOTIFY_INFORMATION buffer[1024];
              FILE_NOTIFY_INFORMATION *pbuffer;
              while (TRUE) 
              { 
                  wcout &lt;&lt; L"waiting..." &lt;&lt; endl;
                  if(ReadDirectoryChangesW(hDir, &amp;buffer, sizeof(buffer),
                      TRUE, FILE_NOTIFY_CHANGE_FILE_NAME| FILE_NOTIFY_CHANGE_LAST_WRITE, 
                      &amp;cbBytes, NULL, NULL)) 
                  { 
                      pbuffer = buffer;
                      do{
                          tmp = pbuffer; 
                          switch(tmp-&gt;Action) 
                          { 
                          case FILE_ACTION_ADDED: 
                              wcout &lt;&lt; L"Directory/File added - " &lt;&lt; getname(tmp) &lt;&lt; endl;
                              break; 
                          case FILE_ACTION_REMOVED:
                              wcout &lt;&lt; L"Directory/File removed - " &lt;&lt; getname(tmp) &lt;&lt; endl;
                              break; 
                          case FILE_ACTION_MODIFIED: 
                              wcout &lt;&lt; L"Directory/File modfied - " &lt;&lt; getname(tmp) &lt;&lt; endl;
                              break; 
                          case FILE_ACTION_RENAMED_OLD_NAME: 
                              wcout &lt;&lt; L"Directory/File old name - " &lt;&lt; getname(tmp) &lt;&lt; endl;
                              break; 
                          case FILE_ACTION_RENAMED_NEW_NAME: 
                              wcout &lt;&lt; L"Directory/File new name - " &lt;&lt; getname(tmp) &lt;&lt; endl;
                              break; 
                          default:
                              wcout &lt;&lt; L"unknown action\n" &lt;&lt; endl;
                              break; 
                          }
                          pbuffer += pbuffer-&gt;NextEntryOffset;
                      }while(pbuffer-&gt;NextEntryOffset);
                  } else
                  {
                      wcout &lt;&lt; "readChangesW failed  now return" &lt;&lt; endl;
                      return;
                  }
              }
          }
  </code></pre>
  
  <p>It looks fine, however, when I'm adding or deleting a large number of files in my directory, it will not report some of the changes, how can I fix this?</p>