|
|
| PFILE_NOTIFY_INFORMATION FileName data not consistent |
|
| Author |
Message |
bdorin

|
Posted: Visual C++ General, PFILE_NOTIFY_INFORMATION FileName data not consistent |
Top |
I am trying to make an application that watches all files modified
within a directory. I began working on the sample provided by msdn but
noticed some strange behaviour: the call to GetQueuedCompletionStatus
is triggered several times for the same file (on the same modification)
and the FileName wchar from PFILE_NOTIFY_INFORMATION has different
strings for the file being modified. It contains the filename followed
by some strange values like $, a box, y with umlaut mark and if more
files are modified in a quick sequence it even contains concatenated
strings representing parts of the 2 filenames. The sample application from
MSDN is only watching files not folders, and they do a compare between
the files they want to watch and the file being modified so they can
discard the filenames that don't match (including those followed by $,
y etc) but if you debug the application you still get them before they are compared.
This is the part where i get the FileName:
void WINAPI HandleDirectoryChange( DWORD dwCompletionPort )
{
DWORD numBytes;
DWORD cbOffset;
LPDIRECTORY_INFO di;
LPOVERLAPPED lpOverlapped;
PFILE_NOTIFY_INFORMATION fni;
do
{
// Retrieve the directory info for this directory
// through the completion key
GetQueuedCompletionStatus( (HANDLE) dwCompletionPort,
&numBytes,
(LPDWORD) &di,
&lpOverlapped,
INFINITE);
if ( di )
{
fni = (PFILE_NOTIFY_INFORMATION)di->lpBuffer;
do
{
cbOffset = fni->NextEntryOffset;
if( fni->Action == FILE_ACTION_MODIFIED )
CheckChangedFile( di, fni );
fni = (PFILE_NOTIFY_INFORMATION)((LPBYTE) fni + cbOffset);
} while( cbOffset );
// Reissue the watch command
ReadDirectoryChangesW( di->hDir,di->lpBuffer,
MAX_BUFFER,
TRUE,
FILE_NOTIFY_CHANGE_LAST_WRITE,
&di->dwBufLength,
&di->Overlapped,
NULL);
}
} while( di );
}
....
// Set up a key(directory info) for each directory
hCompPort=CreateIoCompletionPort( DirInfo[numDirs].hDir,
hCompPort,
(DWORD) &DirInfo[numDirs],
0);
....
ReadDirectoryChangesW( DirInfo .hDir,
DirInfo .lpBuffer,
MAX_BUFFER,
TRUE,
FILE_NOTIFY_CHANGE_LAST_WRITE,
&DirInfo .dwBufLength,&DirInfo .Overlapped,
NULL);
and the structure of DirInfo
typedef struct _DIRECTORY_INFO {
HANDLE hDir;
TCHAR lpszDirName[MAX_PATH];
CHAR lpBuffer[MAX_BUFFER];
DWORD dwBufLength;
OVERLAPPED Overlapped;
}DIRECTORY_INFO, *PDIRECTORY_INFO, *LPDIRECTORY_INFO;
(all this is a copy/paste from the sample)
Anyone knows if this is the expected behaviour If that's
the case are there any workarounds for getting correct file names
PS: is there any way to insert code in the posts (sorry, i didn't find it the faq)
Visual C++9
|
| |
|
| |
 |
| |
|