10-04-2008 09:51 AM - edited 10-04-2008 09:52 AM
Hello
Is there any example using ReadDirectoryChangesW in cvi?
I have to do with a commercial program writing files in a directory tree (quite nested) and I want to develop an application that fetchs data whenever a file/directory is created/appended.
I cannot even compile my trial program.
The following:
----------
#include <windows.h>
#include <winbase.h>
FILE_NOTIFY_INFORMATION* fni;
char filename[32000];
HANDLE hDir;
DWORD bytesret=0;
fni = (FILE_NOTIFY_INFORMATION*) filename;
hDir = CreateFile("d:\temp", GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
if(hDir==INVALID_HANDLE_VALUE) {
MessageBox(NULL,"Failed to get directory handle!","Error",MB_OK);
}
ReadDirectoryChangesW(hDir, fni, 512, 0, FILE_NOTIFY_CHANGE_CREATION|FILE_NOTIFY_CHANGE_SIZE, &bytesret, NULL, NULL);
causes the error
Undefined symbol '_ReadDirectoryChangesW' referenced in whatsoever.c
despite the fact that I added krenel32.lib to the project.
What is missing?
10-04-2008 12:41 PM
First of all, you do not need to include winbase.h, which is already included by windows.h. Definition of ReadDirectoryChangesW in winbase.h is vinculated to the definition of _WIN32_WINNT with a valuegreater to or equal to 4, so you mus t add this definition in your project. Read this answer of BilalD for a reference on this argument. Also. don't forget to add a second backslash in the directory definition ("D:\\temp") since the compiler treats single backslashes as control characters (in this case '\t' will be evaluated as a tab character).
After adding the definition I was able to compile your code and to receive notifications of file changes in the directory.
10-04-2008 02:57 PM
Roberto Bozzolo wrote:First of all, you do not need to include winbase.h, which is already included by windows.h. Definition of ReadDirectoryChangesW in winbase.h is vinculated to the definition of _WIN32_WINNT with a valuegreater to or equal to 4, so you mus t add this definition in your project. Read this answer of BilalD for a reference on this argument. Also.
Thank you, I got it working.
don't forget to add a second backslash in the directory definition ("D:\\temp") since the compiler treats single backslashes as control characters (in this case '\t' will be evaluated as a tab character).
Ooops....