Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. About <b>FindFirstChangeNotification</b> and <b>ReadDirectoryChangeW</b>

About <b>FindFirstChangeNotification</b> and <b>ReadDirectoryChangeW</b>

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++data-structures
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    a_du
    wrote on last edited by
    #1

    hi, i am developing a folder watching application. i want to use the fuction FindFirstChangeNotification and ReadDirectoryChangeW. The problem here is when i create a MFC project using Dialog approach i inlcude the sample code MSDN provide in a button handler function, and if i run it, the application will hung and i have to use task manager to close it. the same thing happen if i use ReadDirectoryChangeW. however if i put the same code in a win32 application project( using MFC shared .dll ), it can works well. Pls help, thanks, the msdn sample code is below: DWORD dwWaitStatus; HANDLE dwChangeHandles[2]; // Watch the C:\WINDOWS directory for file creation and // deletion. dwChangeHandles[0] = FindFirstChangeNotification( "C:\\WINDOWS", // directory to watch FALSE, // do not watch the subtree FILE_NOTIFY_CHANGE_FILE_NAME); // watch file name changes if (dwChangeHandles[0] == INVALID_HANDLE_VALUE) ExitProcess(GetLastError()); // Watch the C:\ subtree for directory creation and // deletion. dwChangeHandles[1] = FindFirstChangeNotification( "C:\\", // directory to watch TRUE, // watch the subtree FILE_NOTIFY_CHANGE_DIR_NAME); // watch dir. name changes if (dwChangeHandles[1] == INVALID_HANDLE_VALUE) ExitProcess(GetLastError()); // Change notification is set. Now wait on both notification // handles and refresh accordingly. while (TRUE) { // Wait for notification. dwWaitStatus = WaitForMultipleObjects(2, dwChangeHandles, FALSE, INFINITE); switch (dwWaitStatus) { case WAIT_OBJECT_0: // A file was created or deleted in C:\WINDOWS. // Refresh this directory and restart the // change notification. RefreshDirectory is an // application-defined function. RefreshDirectory("C:\\WINDOWS") if ( FindNextChangeNotification( dwChangeHandles[0]) == FALSE ) ExitProcess(GetLastError()); break; case WAIT_OBJECT_0 + 1: // A directory was created or deleted in C:\. // Refresh the directory tree and restart the // change notification. RefreshTree is an // application-defined function. RefreshTree("C:\\"); if (FindNextChangeNotification( dwChangeHandles[1]) == F

    T S 2 Replies Last reply
    0
    • A a_du

      hi, i am developing a folder watching application. i want to use the fuction FindFirstChangeNotification and ReadDirectoryChangeW. The problem here is when i create a MFC project using Dialog approach i inlcude the sample code MSDN provide in a button handler function, and if i run it, the application will hung and i have to use task manager to close it. the same thing happen if i use ReadDirectoryChangeW. however if i put the same code in a win32 application project( using MFC shared .dll ), it can works well. Pls help, thanks, the msdn sample code is below: DWORD dwWaitStatus; HANDLE dwChangeHandles[2]; // Watch the C:\WINDOWS directory for file creation and // deletion. dwChangeHandles[0] = FindFirstChangeNotification( "C:\\WINDOWS", // directory to watch FALSE, // do not watch the subtree FILE_NOTIFY_CHANGE_FILE_NAME); // watch file name changes if (dwChangeHandles[0] == INVALID_HANDLE_VALUE) ExitProcess(GetLastError()); // Watch the C:\ subtree for directory creation and // deletion. dwChangeHandles[1] = FindFirstChangeNotification( "C:\\", // directory to watch TRUE, // watch the subtree FILE_NOTIFY_CHANGE_DIR_NAME); // watch dir. name changes if (dwChangeHandles[1] == INVALID_HANDLE_VALUE) ExitProcess(GetLastError()); // Change notification is set. Now wait on both notification // handles and refresh accordingly. while (TRUE) { // Wait for notification. dwWaitStatus = WaitForMultipleObjects(2, dwChangeHandles, FALSE, INFINITE); switch (dwWaitStatus) { case WAIT_OBJECT_0: // A file was created or deleted in C:\WINDOWS. // Refresh this directory and restart the // change notification. RefreshDirectory is an // application-defined function. RefreshDirectory("C:\\WINDOWS") if ( FindNextChangeNotification( dwChangeHandles[0]) == FALSE ) ExitProcess(GetLastError()); break; case WAIT_OBJECT_0 + 1: // A directory was created or deleted in C:\. // Refresh the directory tree and restart the // change notification. RefreshTree is an // application-defined function. RefreshTree("C:\\"); if (FindNextChangeNotification( dwChangeHandles[1]) == F

      T Offline
      T Offline
      ThatsAlok
      wrote on last edited by
      #2

      a_du wrote: dwWaitStatus = WaitForMultipleObjects(2, dwChangeHandles, FALSE, INFINITE); Actaully this is BLOCKING CALL,this will block all Message Coming to your Dialog Box. Only Solution to above problem is to create multithread Program!

      "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

      cheers, Alok Gupta

      A 1 Reply Last reply
      0
      • T ThatsAlok

        a_du wrote: dwWaitStatus = WaitForMultipleObjects(2, dwChangeHandles, FALSE, INFINITE); Actaully this is BLOCKING CALL,this will block all Message Coming to your Dialog Box. Only Solution to above problem is to create multithread Program!

        "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

        cheers, Alok Gupta

        A Offline
        A Offline
        a_du
        wrote on last edited by
        #3

        Thanx alot. I have solved that problem by using multithread. BTW, can some one tell me the differences between these two functions and whether it is possible to retrieve file name informations from the FindFirstChangeNotification approach.

        T 1 Reply Last reply
        0
        • A a_du

          hi, i am developing a folder watching application. i want to use the fuction FindFirstChangeNotification and ReadDirectoryChangeW. The problem here is when i create a MFC project using Dialog approach i inlcude the sample code MSDN provide in a button handler function, and if i run it, the application will hung and i have to use task manager to close it. the same thing happen if i use ReadDirectoryChangeW. however if i put the same code in a win32 application project( using MFC shared .dll ), it can works well. Pls help, thanks, the msdn sample code is below: DWORD dwWaitStatus; HANDLE dwChangeHandles[2]; // Watch the C:\WINDOWS directory for file creation and // deletion. dwChangeHandles[0] = FindFirstChangeNotification( "C:\\WINDOWS", // directory to watch FALSE, // do not watch the subtree FILE_NOTIFY_CHANGE_FILE_NAME); // watch file name changes if (dwChangeHandles[0] == INVALID_HANDLE_VALUE) ExitProcess(GetLastError()); // Watch the C:\ subtree for directory creation and // deletion. dwChangeHandles[1] = FindFirstChangeNotification( "C:\\", // directory to watch TRUE, // watch the subtree FILE_NOTIFY_CHANGE_DIR_NAME); // watch dir. name changes if (dwChangeHandles[1] == INVALID_HANDLE_VALUE) ExitProcess(GetLastError()); // Change notification is set. Now wait on both notification // handles and refresh accordingly. while (TRUE) { // Wait for notification. dwWaitStatus = WaitForMultipleObjects(2, dwChangeHandles, FALSE, INFINITE); switch (dwWaitStatus) { case WAIT_OBJECT_0: // A file was created or deleted in C:\WINDOWS. // Refresh this directory and restart the // change notification. RefreshDirectory is an // application-defined function. RefreshDirectory("C:\\WINDOWS") if ( FindNextChangeNotification( dwChangeHandles[0]) == FALSE ) ExitProcess(GetLastError()); break; case WAIT_OBJECT_0 + 1: // A directory was created or deleted in C:\. // Refresh the directory tree and restart the // change notification. RefreshTree is an // application-defined function. RefreshTree("C:\\"); if (FindNextChangeNotification( dwChangeHandles[1]) == F

          S Offline
          S Offline
          S Senthil Kumar
          wrote on last edited by
          #4

          As Alok said, you're blocking the UI thread and waiting for directory changes. You need to move that code to a separate worker thread and inform the UI when you get modifications. Regards Senthil _____________________________ My Blog | My Articles | WinMacro

          T 1 Reply Last reply
          0
          • A a_du

            Thanx alot. I have solved that problem by using multithread. BTW, can some one tell me the differences between these two functions and whether it is possible to retrieve file name informations from the FindFirstChangeNotification approach.

            T Offline
            T Offline
            ThatsAlok
            wrote on last edited by
            #5

            a_du wrote: it is possible to retrieve file name informations from the FindFirstChangeNotification approach. Nope, It not Possible to Retrieve File Information using FindFirstChangeNotification approach!, only ReadDirectoryChangeW will help in this regard!

            "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

            cheers, Alok Gupta

            1 Reply Last reply
            0
            • S S Senthil Kumar

              As Alok said, you're blocking the UI thread and waiting for directory changes. You need to move that code to a separate worker thread and inform the UI when you get modifications. Regards Senthil _____________________________ My Blog | My Articles | WinMacro

              T Offline
              T Offline
              ThatsAlok
              wrote on last edited by
              #6

              S. Senthil Kumar wrote: and inform the UI when you get modifications. Oops, I forget to mention that, Thanks for correcting me! :)

              "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

              cheers, Alok Gupta

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups