Windows监则目录文件变化事件响应
2022-10-13
46
0
//
//unsigned long __stdcall notificationThread(void* parameter)
//{
// char buff[100] = { 0 };
// HANDLE notificationHandle = FindFirstChangeNotificationW(
// L"C:\\XX\DD\\", true, FILE_NOTIFY_CHANGE_FILE_NAME | FILE_NOTIFY_CHANGE_LAST_WRITE);
//
// hShutDownEvent = CreateEventW(NULL, true, false, NULL);;
// sprintf_s(buff, sizeof(buff), "hShutDownEvent=0x%p\n", hShutDownEvent);
// OutputDebugStringA(buff);
//
// HANDLE handles[2] = { hShutDownEvent, notificationHandle };
// while (true)
// {
// DWORD which = WaitForMultipleObjects(2, handles, false, INFINITE);
// OutputDebugStringA("Device Change\n");
// DWORD e = GetLastError();
// if (which == WAIT_OBJECT_0)//hShutDownEvent
// {
// OutputDebugStringA("break out\n");
// break;
// }
// else if (which == WAIT_OBJECT_0 + 1) //notificationHandle
// {
// OutputDebugStringA("begin open file\n");
// std::string str;
// GetBufferFromFile(L"\\??\\C:\\XX\\DD\\config.txt", str);
// OutputDebugStringA("end open file\n");
//
// memset(buff, 0, sizeof(buff));
// if (str.size())
// {
// memcpy(buff, &str.at(0), str.size());
// nDelay = atoi(buff);
// sprintf_s(buff, sizeof(buff), "nDealay=%d\n", nDelay);
// OutputDebugStringA(buff);
// }
//
// FindNextChangeNotification(notificationHandle);
// }
// else
// {
// sprintf_s(buff, sizeof(buff), "which=%0x err=0x%x\n", which,e);
// OutputDebugStringA(buff);
// }
// }
// FindCloseChangeNotification(notificationHandle);
//
// OutputDebugStringA("notificationThread thread exit\n");
// return 0;
//}