Hello I have a problem
I'm watching for a files by
ReadDirectoryChangesW
that's my thread where I'm waiting for packets:
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);
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
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
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!