Does anyone know the proper way to use ReadDirectoryChangesW? Or, does anyone have an alternative function I can use? Ultimately, I want to keep track of the progress of a file writing operation, and I thought this was one possible way.
What I've tried is this:
I figured I was doing something wrong and would crash/freeze my program, but no such luck--I just receive error code 6: ERROR_INVALID_HANDLE. This makes me think that I'm somehow using CreateFile incorrectly, but I copied it exactly from the documentation :confused:Code:
HANDLE hDir = CreateFile(directory, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
MessageBox(NULL,"Failed to get directory handle!","Error",MB_OK);
FILE_NOTIFY_INFORMATION* fni= (FILE_NOTIFY_INFORMATION*)new char; //how do I know how large a buffer to allocate?
if(!ReadDirectoryChangesW(hDir, &fni, 512, 0, FILE_NOTIFY_CHANGE_CREATION|FILE_NOTIFY_CHANGE_SIZE, &bytesret, &ol, ProgressRoutine))
Edit: Just realized I was checking the return of CreateFile improperly. It returns INVALID_HANDLE_VALUE and GetLastError() returns 2: ERROR_FILE_NOT_FOUND, but I've checked the string and the directory does exist...