hello, i just started a new job and it requires c++, and i'm confused trying to implement a simple program which watches a file for changes.
i followed a tutorial and sample code online, and i'm trying to implement the asynchronous version using CreateFile and ReadDirectoryChangesW with a completion routine. the code seems to work fine, but only does depending on how i program the message loop.
if i use the "standard" message loop:
Code:
while (GetMessage(&msg, NULL, 0, 0) > 0) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
the breakpoint i set in the completion function never hits. nothing seems to happen. however, if i use the following code:
Code:
while (true) {
while (WAIT_IO_COMPLETION == MsgWaitForMultipleObjectsEx(0, NULL, INFINITE, QS_ALLINPUT, MWMO_ALERTABLE))
/* Do nothing */;
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
if (msg.message == WM_QUIT) {
return 0;
}
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
it works...
what's the difference? thanks.