LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

using ReadDirectoryChangesW in CVI (not Labview)

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?

 

 

Message Edited by atrac on 10-04-2008 09:52 AM
0 Kudos
Message 1 of 3
(3,091 Views)

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.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 3
(3,079 Views)

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.Smiley Happy

 


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....Smiley Very Happy

0 Kudos
Message 3 of 3
(3,072 Views)