I need to retrieve a handle to a directory to be able to call ReadDirectoryChangesW on it. Actually I would need a bit more than that but let’s go easy first. I have narrowed down the problem to this:
m_directoryHandle = CreateFileA(
"C:\\Users\\victor\\Documents\\Projets\\libxnotify\\unittests", // __in LPCTSTR lpFileName,
FILE_LIST_DIRECTORY, // __in DWORD dwDesiredAccess,
0, // __in DWORD dwShareMode,
0, // __in_opt LPSECURITY_ATTRIBUTES lpSecurityAttributes,
OPEN_EXISTING, // __in DWORD dwCreationDisposition,
0, // __in DWORD dwFlagsAndAttributes,
0 // __in_opt HANDLE hTemplateFile
);
This return an INVALID_HANDLE_VALUE with a last error code of ERROR_ACCESS_DENIED. Needless to say, I have tried oodles of different parameters, none on them did work. I run my program as victor, and to make sure I really had the rights in that unittests directory, I opened a command shell and typed:
C:\Users\victor>echo bla >> "C:\Users\victor\Documents\Projets\libxnotify\unittests\test"
and it worked.
The documentation for ReadDirectoryChangesW has a remark that states:
The documentation for CreateFile then also has a more detailed remark about this:
You’re missing out on this important
FILE_FLAG_BACKUP_SEMANTICSflag fordwFlagsAndAttributes.