ReadDirectoryChangesW Problem~~~
-
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";
-
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";
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
-
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
-
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
-
i know Change Journal now but if i wanna it works on NTFS how should i do still:confused::confused:
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
-
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
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??
-
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??
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
-
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