Click here to Skip to main content
15,914,013 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRefresh problem Pin
Raul Simcic14-Mar-05 22:07
Raul Simcic14-Mar-05 22:07 
GeneralWindows98 problem Pin
Raul Simcic14-Mar-05 21:37
Raul Simcic14-Mar-05 21:37 
GeneralRe: Windows98 problem Pin
ThatsAlok14-Mar-05 22:02
ThatsAlok14-Mar-05 22:02 
GeneralRe: Windows98 problem Pin
Raul Simcic14-Mar-05 22:20
Raul Simcic14-Mar-05 22:20 
GeneralRe: Windows98 problem Pin
fire1234515-Mar-05 0:47
fire1234515-Mar-05 0:47 
GeneralRe: Windows98 problem Pin
David Crow15-Mar-05 2:45
David Crow15-Mar-05 2:45 
GeneralRe: Windows98 problem Pin
Raul Simcic15-Mar-05 7:18
Raul Simcic15-Mar-05 7:18 
GeneralProblem to terminate thread when using ReadDirectoryChangesW Pin
ledallam14-Mar-05 21:28
ledallam14-Mar-05 21:28 
Hi
I am working in MFC. In my application, I wrote a thread function which continouly checks for a update in a file in one particular directory. This thread should stop when clicked on a button. I have used ReadDirectoryChangesW for getting notification of the file change. To end the thread I waited on a STOP event i.e checking for it to end the thread.
But the m_StopEvent event is not caught beacuse the control is stuck at while( ReadDirectoryChangesW) I mean it not going inside the while loop unless ReadDirectoryChangesW returns true.


UINT CheckFileUpdates(LPVOID lp)
{
//Get the document pointer
CLogViewerAppView* pView = (CLogViewerAppView*)lp;
CLogViewerAppDoc* pDoc = pView->GetDocument();

CFileException err;
CFileStatus st;
CFile::GetStatus(pView->m_LogFilePath,st);
LONG l1,l2;

CFile file;
if( !file.Open(pView->m_LogFilePath, CFile::modeRead|CFile::shareDenyNone, &err ) )
{
TCHAR szCause[255];
err.GetErrorMessage(szCause, 255);
AfxMessageBox(szCause);
return 0;
}
l1 = (LONG)file.GetLength();
file.Close();
CFile file1;
LONG size_1 = (LONG)st.m_size;
int len = pView->m_LogFilePath.GetLength()-pView->m_LogFileName.GetLength()-1;
CString dir = pView->m_LogFilePath.Left(len);
HANDLE hDir = CreateFile( dir, // pointer to the file name
FILE_LIST_DIRECTORY, // access (read/write) mode
FILE_SHARE_READ|FILE_SHARE_WRITE, // share mode
NULL, // security descriptor
OPEN_EXISTING, // how to create
FILE_FLAG_BACKUP_SEMANTICS, // file attributes
NULL // file with attributes to copy
);

FILE_NOTIFY_INFORMATION Buffer[1024];
DWORD BytesReturned;

while( ReadDirectoryChangesW(
hDir,
&Buffer,
sizeof(Buffer),
TRUE,
FILE_NOTIFY_CHANGE_SIZE, conditions
&BytesReturned, // bytes returned
NULL, // overlapped buffer
NULL// completion routine
))
{
if ( WaitForSingleObject(pView->m_StopEvent, 1) == WAIT_OBJECT_0 )
{
OutputDebugString(_T("\n KILL THE THREAD\n"));
return 0; //end the thread

}

CString fileName(Buffer[0].FileName);
fileName = fileName.Left(Buffer[0].FileNameLength / 2);

if(fileName.CompareNoCase(pView->m_LogFileName) == 0)
{
//Do the work
}
}

return 0;
}


Can anyone please help me to proceed further. I do not want to end the thraed from outside the function as it may cause memory leaks.

Thanks
Madhavi
GeneralRe: Problem to terminate thread when using ReadDirectoryChangesW Pin
Anonymous14-Mar-05 23:12
Anonymous14-Mar-05 23:12 
QuestionHow to write CDB to scsi device? Pin
ErisonWu14-Mar-05 20:43
ErisonWu14-Mar-05 20:43 
GeneralMouse event , ActiveX control Pin
Anand for every one14-Mar-05 19:37
Anand for every one14-Mar-05 19:37 
Questionhow to get every data in Visual C++ From SQL Database and store in an array Pin
reenacutie14-Mar-05 18:40
reenacutie14-Mar-05 18:40 
AnswerRe: how to get every data in Visual C++ From SQL Database and store in an array Pin
Anonymous14-Mar-05 20:38
Anonymous14-Mar-05 20:38 
AnswerRe: how to get every data in Visual C++ From SQL Database and store in an array Pin
David Crow15-Mar-05 2:51
David Crow15-Mar-05 2:51 
GeneralPlease help-about Modal dialog boxe Pin
SmitaG14-Mar-05 18:10
SmitaG14-Mar-05 18:10 
GeneralHELP ME!!! Pin
Anonymous14-Mar-05 17:56
Anonymous14-Mar-05 17:56 
GeneralRe: HELP ME!!! Pin
Yulianto.14-Mar-05 18:31
Yulianto.14-Mar-05 18:31 
GeneralRe: HELP ME!!! Pin
Anonymous15-Mar-05 1:45
Anonymous15-Mar-05 1:45 
GeneralRe: HELP ME!!! Pin
ThatsAlok14-Mar-05 18:51
ThatsAlok14-Mar-05 18:51 
GeneralRe: HELP ME!!! Pin
fire1234515-Mar-05 0:52
fire1234515-Mar-05 0:52 
GeneralRe: HELP ME!!! Pin
Anonymous15-Mar-05 1:46
Anonymous15-Mar-05 1:46 
GeneralRe: HELP ME!!! Pin
ThatsAlok15-Mar-05 3:10
ThatsAlok15-Mar-05 3:10 
GeneralNeed Help for Writing WebService Client Pin
covansys200014-Mar-05 17:28
covansys200014-Mar-05 17:28 
GeneralUSEAGE OF FUNCTION AND DECLARATION OF FUNCTION IN CPP Pin
phijophlip14-Mar-05 17:27
phijophlip14-Mar-05 17:27 
GeneralRe: USEAGE OF FUNCTION AND DECLARATION OF FUNCTION IN CPP Pin
S. Senthil Kumar14-Mar-05 18:09
S. Senthil Kumar14-Mar-05 18:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.