Click here to Skip to main content
15,897,226 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello I have a problem

I'm watching for a files by
C++
ReadDirectoryChangesW


that's my thread where I'm waiting for packets:

C++
CFileMonitoringManager *pThisClass = (CFileMonitoringManager*)lpParam;

	TCHAR szFileNameBuffer[MAX_PATH];
	DWORD dwBytes = 0;
	DWORD cbOffset = 0;
	CSubscribeTarget *pObject = NULL;
	LPOVERLAPPED lpOverlapped = NULL;    
	FILE_NOTIFY_INFORMATION *pNotifyInfo = NULL;

	BOOL bTwoTimes = FALSE;

	while(pThisClass->m_hCompPort)
	{
          if (::GetQueuedCompletionStatus(pThisClass->m_hCompPort, &dwBytes, 
(LPDWORD)&pObject, &lpOverlapped,  INFINITE))
		{
	          pNotifyInfo = (PFILE_NOTIFY_INFORMATION)pObject->m_NotifyBuffer;
		  DWORD dwBytesRead = 0;

		  do
		  {
                       memset(szFileNameBuffer, 0, sizeof(TCHAR) * MAX_PATH);
                       TCHAR* szFileName = 
GetTCHAR(pNotifyInfo->FileName, pNotifyInfo->FileNameLength, szFileNameBuffer, MAX_PATH);
		
                       //My special code
		       cbOffset = pNotifyInfo->NextEntryOffset;
		pNotifyInfo = (PFILE_NOTIFY_INFORMATION)((LPBYTE)pNotifyInfo + cbOffset);
		  } 
		   while(cbOffset);

		lpOverlapped->Offset += dwBytes;

		if(!pObject->ReadingDirectory())
			return 0;
		}
		pNotifyInfo = NULL;
		dwBytes = 0;
		lpOverlapped = NULL;
		pObject = NULL;


For example I watching for directory and file D:\TESTS\Input.txt.
When I'm changing some another file like D:\TESTS\Input1.txt, I get notification
C++
pNotifyInfo->FileName
is good name Input1.txt and length 20, I skip my special code. But next time when I change D:\TESTS\Input.txt I get in
C++
pNotifyInfo->FileName
Input.txtt and Length 18. Why?
I tried NULLed all params but it didn't help.

Please help me I can't understand why I get wrong name like buffer wasn't clean.
Thank you!
Posted
Updated 22-Aug-13 0:13am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900