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
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. ReadDirectoryChangesW Problem~~~

ReadDirectoryChangesW Problem~~~

Scheduled Pinned Locked Moved C / C++ / MFC
securityhelptutorialannouncement
8 Posts 2 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.
  • Y Offline
    Y Offline
    york528
    wrote on last edited by
    #1

    when i spy the dictionary why some file create,delete,rename or resize,etc couldn't be spy and when file update quickly it will miss some of them this is the code from a filespy demo

    static void Action(CSpyDlg* dlg)
    {
    //CWnd* hwnd = AfxGetMainWnd();
    USES_CONVERSION;

    HANDLE hDir = CreateFile( CString("d:"), // pointer to the file name
    	FILE\_LIST\_DIRECTORY,                // access (read/write) mode
    	FILE\_SHARE\_READ|FILE\_SHARE\_DELETE,  // share mode
    	NULL,                               // security descriptor
    	OPEN\_EXISTING,                      // how to create
    	FILE\_FLAG\_BACKUP\_SEMANTICS|FILE\_FLAG\_OVERLAPPED,         // file attributes
    	NULL                                // file with attributes to copy
    	);
    	/\*
    	HANDLE hDir = CreateFile( CString("d:"), // pointer to the file name
    	FILE\_LIST\_DIRECTORY,                // access (read/write) mode
    	FILE\_SHARE\_READ|FILE\_SHARE\_DELETE,  // share mode
    	NULL,                               // security descriptor
    	OPEN\_EXISTING|CREATE\_NEW|CREATE\_ALWAYS|OPEN\_ALWAYS|TRUNCATE\_EXISTING,                      // how to create
    	FILE\_FLAG\_BACKUP\_SEMANTICS|FILE\_ATTRIBUTE\_ARCHIVE|FILE\_ATTRIBUTE\_ENCRYPTED|
    	FILE\_ATTRIBUTE\_HIDDEN|FILE\_ATTRIBUTE\_NOT\_CONTENT\_INDEXED|
    	FILE\_ATTRIBUTE\_OFFLINE|FILE\_ATTRIBUTE\_READONLY|FILE\_ATTRIBUTE\_SYSTEM|FILE\_ATTRIBUTE\_TEMPORARY,         // file attributes
    	NULL                                // file with attributes to copy
    	);
    \*/
    FILE\_NOTIFY\_INFORMATION Buffer\[1024\];
    DWORD BytesReturned;
    while(ReadDirectoryChangesW(
    	hDir,                                  // handle to directory
    	&Buffer,                                    // read results buffer
    	sizeof(Buffer),                                // length of buffer
    	TRUE,                                 // monitoring option
    	FILE\_NOTIFY\_CHANGE\_SECURITY|
    	FILE\_NOTIFY\_CHANGE\_CREATION|
    	FILE\_NOTIFY\_CHANGE\_LAST\_ACCESS|
    	FILE\_NOTIFY\_CHANGE\_LAST\_WRITE|
    	FILE\_NOTIFY\_CHANGE\_SIZE|
    	FILE\_NOTIFY\_CHANGE\_ATTRIBUTES|
    	FILE\_NOTIFY\_CHANGE\_DIR\_NAME|
    	FILE\_NOTIFY\_CHANGE\_FILE\_NAME,             // filter conditions
    	&BytesReturned,              // bytes returned
    	NULL,                          // overlapped buffer
    	NULL// completion routine
    	))
    {
    	CTime tm = CTime::GetCurrentTime();
    	
    	CString helper\_txt;
    	
    	switch(Buffer\[0\].Action)
    	{
    	case FILE\_ACTION\_ADDED: helper\_txt = "The file was added to the directory"; break; 
    	case FILE\_ACTION\_REMOVED: helper\_txt = "The file was removed from the directory";
    
    N 1 Reply Last reply
    0
    • Y york528

      when i spy the dictionary why some file create,delete,rename or resize,etc couldn't be spy and when file update quickly it will miss some of them this is the code from a filespy demo

      static void Action(CSpyDlg* dlg)
      {
      //CWnd* hwnd = AfxGetMainWnd();
      USES_CONVERSION;

      HANDLE hDir = CreateFile( CString("d:"), // pointer to the file name
      	FILE\_LIST\_DIRECTORY,                // access (read/write) mode
      	FILE\_SHARE\_READ|FILE\_SHARE\_DELETE,  // share mode
      	NULL,                               // security descriptor
      	OPEN\_EXISTING,                      // how to create
      	FILE\_FLAG\_BACKUP\_SEMANTICS|FILE\_FLAG\_OVERLAPPED,         // file attributes
      	NULL                                // file with attributes to copy
      	);
      	/\*
      	HANDLE hDir = CreateFile( CString("d:"), // pointer to the file name
      	FILE\_LIST\_DIRECTORY,                // access (read/write) mode
      	FILE\_SHARE\_READ|FILE\_SHARE\_DELETE,  // share mode
      	NULL,                               // security descriptor
      	OPEN\_EXISTING|CREATE\_NEW|CREATE\_ALWAYS|OPEN\_ALWAYS|TRUNCATE\_EXISTING,                      // how to create
      	FILE\_FLAG\_BACKUP\_SEMANTICS|FILE\_ATTRIBUTE\_ARCHIVE|FILE\_ATTRIBUTE\_ENCRYPTED|
      	FILE\_ATTRIBUTE\_HIDDEN|FILE\_ATTRIBUTE\_NOT\_CONTENT\_INDEXED|
      	FILE\_ATTRIBUTE\_OFFLINE|FILE\_ATTRIBUTE\_READONLY|FILE\_ATTRIBUTE\_SYSTEM|FILE\_ATTRIBUTE\_TEMPORARY,         // file attributes
      	NULL                                // file with attributes to copy
      	);
      \*/
      FILE\_NOTIFY\_INFORMATION Buffer\[1024\];
      DWORD BytesReturned;
      while(ReadDirectoryChangesW(
      	hDir,                                  // handle to directory
      	&Buffer,                                    // read results buffer
      	sizeof(Buffer),                                // length of buffer
      	TRUE,                                 // monitoring option
      	FILE\_NOTIFY\_CHANGE\_SECURITY|
      	FILE\_NOTIFY\_CHANGE\_CREATION|
      	FILE\_NOTIFY\_CHANGE\_LAST\_ACCESS|
      	FILE\_NOTIFY\_CHANGE\_LAST\_WRITE|
      	FILE\_NOTIFY\_CHANGE\_SIZE|
      	FILE\_NOTIFY\_CHANGE\_ATTRIBUTES|
      	FILE\_NOTIFY\_CHANGE\_DIR\_NAME|
      	FILE\_NOTIFY\_CHANGE\_FILE\_NAME,             // filter conditions
      	&BytesReturned,              // bytes returned
      	NULL,                          // overlapped buffer
      	NULL// completion routine
      	))
      {
      	CTime tm = CTime::GetCurrentTime();
      	
      	CString helper\_txt;
      	
      	switch(Buffer\[0\].Action)
      	{
      	case FILE\_ACTION\_ADDED: helper\_txt = "The file was added to the directory"; break; 
      	case FILE\_ACTION\_REMOVED: helper\_txt = "The file was removed from the directory";
      
      N Offline
      N Offline
      Nibu babu thomas
      wrote on last edited by
      #2

      york528 wrote:

      and when file update quickly it will miss some of them

      Here's a solution from MSDN (for NTFS drives) -> http://www.microsoft.com/msj/0999/journal/journal.aspx[^]

      Nibu thomas Microsoft MVP for VC++ Code must be written to be read, not by the compiler, but by another human being. Programming Blog: http://nibuthomas.wordpress.com

      modified on Thursday, June 12, 2008 11:49 PM

      Y 2 Replies Last reply
      0
      • N Nibu babu thomas

        york528 wrote:

        and when file update quickly it will miss some of them

        Here's a solution from MSDN (for NTFS drives) -> http://www.microsoft.com/msj/0999/journal/journal.aspx[^]

        Nibu thomas Microsoft MVP for VC++ Code must be written to be read, not by the compiler, but by another human being. Programming Blog: http://nibuthomas.wordpress.com

        modified on Thursday, June 12, 2008 11:49 PM

        Y Offline
        Y Offline
        york528
        wrote on last edited by
        #3

        you're right this function dosen't work on NTFS volume when i tried on FAT32 volume it works well thank you

        1 Reply Last reply
        0
        • N Nibu babu thomas

          york528 wrote:

          and when file update quickly it will miss some of them

          Here's a solution from MSDN (for NTFS drives) -> http://www.microsoft.com/msj/0999/journal/journal.aspx[^]

          Nibu thomas Microsoft MVP for VC++ Code must be written to be read, not by the compiler, but by another human being. Programming Blog: http://nibuthomas.wordpress.com

          modified on Thursday, June 12, 2008 11:49 PM

          Y Offline
          Y Offline
          york528
          wrote on last edited by
          #4

          i know Change Journal now but if i wanna it works on NTFS how should i do still:confused::confused:

          N 1 Reply Last reply
          0
          • Y york528

            i know Change Journal now but if i wanna it works on NTFS how should i do still:confused::confused:

            N Offline
            N Offline
            Nibu babu thomas
            wrote on last edited by
            #5

            york528 wrote:

            but if i wanna it works on NTFS how should i do still [Confused] [Confused]

            There is a sample application attached with source -> http://download.microsoft.com/download/0/6/7/0678184e-905e-4783-9511-d4dca1f492b4/ChangeJournal.exe[^] Sorry for the delay!

            Nibu thomas Microsoft MVP for VC++ Code must be written to be read, not by the compiler, but by another human being. Programming Blog: http://nibuthomas.wordpress.com

            Y 1 Reply Last reply
            0
            • N Nibu babu thomas

              york528 wrote:

              but if i wanna it works on NTFS how should i do still [Confused] [Confused]

              There is a sample application attached with source -> http://download.microsoft.com/download/0/6/7/0678184e-905e-4783-9511-d4dca1f492b4/ChangeJournal.exe[^] Sorry for the delay!

              Nibu thomas Microsoft MVP for VC++ Code must be written to be read, not by the compiler, but by another human being. Programming Blog: http://nibuthomas.wordpress.com

              Y Offline
              Y Offline
              york528
              wrote on last edited by
              #6

              the demo got some error error C2065: 'USN_JOURNAL_DATA' : undeclared identifier error C2146: syntax error : missing ';' before identifier 'ujd' error C2065: 'ujd' : undeclared identifier error C2065: 'FSCTL_QUERY_USN_JOURNAL' : undeclared identifier error C2228: left of '.UsnJournalID' must have class/struct/union type error C2228: left of '.FirstUsn' must have class/struct/union type error C2228: left of '.NextUsn' must have class/struct/union type error C2228: left of '.LowestValidUsn' must have class/struct/union type error C2228: left of '.MaxUsn' must have class/struct/union type error C2228: left of '.MaximumSize' must have class/struct/union type error C2228: left of '.AllocationDelta' must have class/struct/union type error C2228: left of '.FirstUsn' must have class/struct/union type error C2039: 'UsnJournalID' : is not a member of 'READ_USN_JOURNAL_DATA' c:\program files\microsoft visual studio\vc98\include\winioctl.h(1873) : see declaration of 'READ_USN_JOURNAL_DATA' error C2228: left of '.UsnJournalID' must have class/struct/union type error C2039: 'FileNameOffset' : is not a member of 'USN_RECORD' c:\program files\microsoft visual studio\vc98\include\winioctl.h(1895) : see declaration of 'USN_RECORD' is there some header file not included??

              N 1 Reply Last reply
              0
              • Y york528

                the demo got some error error C2065: 'USN_JOURNAL_DATA' : undeclared identifier error C2146: syntax error : missing ';' before identifier 'ujd' error C2065: 'ujd' : undeclared identifier error C2065: 'FSCTL_QUERY_USN_JOURNAL' : undeclared identifier error C2228: left of '.UsnJournalID' must have class/struct/union type error C2228: left of '.FirstUsn' must have class/struct/union type error C2228: left of '.NextUsn' must have class/struct/union type error C2228: left of '.LowestValidUsn' must have class/struct/union type error C2228: left of '.MaxUsn' must have class/struct/union type error C2228: left of '.MaximumSize' must have class/struct/union type error C2228: left of '.AllocationDelta' must have class/struct/union type error C2228: left of '.FirstUsn' must have class/struct/union type error C2039: 'UsnJournalID' : is not a member of 'READ_USN_JOURNAL_DATA' c:\program files\microsoft visual studio\vc98\include\winioctl.h(1873) : see declaration of 'READ_USN_JOURNAL_DATA' error C2228: left of '.UsnJournalID' must have class/struct/union type error C2039: 'FileNameOffset' : is not a member of 'USN_RECORD' c:\program files\microsoft visual studio\vc98\include\winioctl.h(1895) : see declaration of 'USN_RECORD' is there some header file not included??

                N Offline
                N Offline
                Nibu babu thomas
                wrote on last edited by
                #7

                You need to install latest platform SDK or if you have the SDK installed change move latest SDK "include path" to top here -> Tools->Options->Directories. I had similar errors! :)

                Nibu thomas Microsoft MVP for VC++ Code must be written to be read, not by the compiler, but by another human being. Programming Blog: http://nibuthomas.wordpress.com

                Y 1 Reply Last reply
                0
                • N Nibu babu thomas

                  You need to install latest platform SDK or if you have the SDK installed change move latest SDK "include path" to top here -> Tools->Options->Directories. I had similar errors! :)

                  Nibu thomas Microsoft MVP for VC++ Code must be written to be read, not by the compiler, but by another human being. Programming Blog: http://nibuthomas.wordpress.com

                  Y Offline
                  Y Offline
                  york528
                  wrote on last edited by
                  #8

                  where i can get latest platform SDK my ide is VC6.0 i am a Chinese so sometimes i can't quite understand correctly Thanks a lot ;) ;)

                  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