Johan M
May 21st, 1999, 07:02 AM
I have a thread running that should determine if a change has occurred in a folder.
The program looks like this:
class Prg
{
static UINT poll_thread(LPVOID);
private:
CString pref_jobdir_m;
...
};
void Prg::test() {
pref_jobdir_m = "c:/jobs/";
CWinThread *thread_handle = AfxBeginThread(Prg::poll_thread, &pref_jobdir_m);
}
UINT Prg::poll_thread(LPVOID parameter) {
char *dir_name = (char*)parameter; // Question 1: is this correct ?!?
HANDLE watch_handle = FindFirstChangeNotification(dir_name, FALSE, FILE_NOTIFY_CHANGE_FILE_NAME);
if (watch_handle != INVALID_HANDLE_VALUE) {
while (TRUE) {
if (WaitForSingleObject(watch_handle, INFINITE) == WAIT_OBJECT_0)
{
MessageBeep(-1);
// Do some extensive time consuming search here of the checked directory
FindNextChangeNotification(watch_handle); // Question 2: Do this before or after the search?
}
}
FindCloseChangeNotification(watch_handle); // the thread won't reach this line anyway...
}
return 0;
}
However, it doesn't work as it seems like the thread can't interpretate my path pref_jobdir_m correctly.
I have two question:
1) I want to pass the path pref_jobdir_m to the thread. However, converting parameter to
a char* doesn't work. How do I do this (check the comment)
2) Should I call FindNextChangeNotification() before or after the thread searches though the
watched directory? I don't want to miss any new events. What if two events appears in a short time?
By the way, I am not using ReadDirectoryChangesW as the compiler won't recognize it. I have Win NT 4.0...
The program looks like this:
class Prg
{
static UINT poll_thread(LPVOID);
private:
CString pref_jobdir_m;
...
};
void Prg::test() {
pref_jobdir_m = "c:/jobs/";
CWinThread *thread_handle = AfxBeginThread(Prg::poll_thread, &pref_jobdir_m);
}
UINT Prg::poll_thread(LPVOID parameter) {
char *dir_name = (char*)parameter; // Question 1: is this correct ?!?
HANDLE watch_handle = FindFirstChangeNotification(dir_name, FALSE, FILE_NOTIFY_CHANGE_FILE_NAME);
if (watch_handle != INVALID_HANDLE_VALUE) {
while (TRUE) {
if (WaitForSingleObject(watch_handle, INFINITE) == WAIT_OBJECT_0)
{
MessageBeep(-1);
// Do some extensive time consuming search here of the checked directory
FindNextChangeNotification(watch_handle); // Question 2: Do this before or after the search?
}
}
FindCloseChangeNotification(watch_handle); // the thread won't reach this line anyway...
}
return 0;
}
However, it doesn't work as it seems like the thread can't interpretate my path pref_jobdir_m correctly.
I have two question:
1) I want to pass the path pref_jobdir_m to the thread. However, converting parameter to
a char* doesn't work. How do I do this (check the comment)
2) Should I call FindNextChangeNotification() before or after the thread searches though the
watched directory? I don't want to miss any new events. What if two events appears in a short time?
By the way, I am not using ReadDirectoryChangesW as the compiler won't recognize it. I have Win NT 4.0...