LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to configure inputs to ReadDirectoryChangesW

Hi all,
I'm trying to make a Watched Folder program using the Windows API function ReadDirectoryChangesW.
Attached is a test program which uses CreateFileA to open a handle to a directory, passes the handle to ReadDirectoryChangesW which waits for a change in the directory, and then closes the handle with CloseHandle.

The test performs correctly, in that a handle is created and ReadDirectoryChangesW does wait for a change to the watched path, but I can't get any information about the change from the File_Notify_Information structure that is supposed to contain the changed path.

If we can get this working, it could serve as a good example for how to configure Call Library Function Node for more complex API's. 
I think I'm close, but I haven't been able to sort out the finer points of passing structs from LV to Windows API functions.

Can you see what I'm doing wrong?

Thanks,
Victor

0 Kudos
Message 1 of 5
(4,003 Views)
Heh,
I actually had myself convinced that ReadDirectoryChangesW was the best way to go about implementing a watched folder routine. 
In actuality, there is something called .NET that does a lot of nifty crap.

I was fortunate to stumble upon a post by  Jarrod S. where he included sample code using the .NET class FileSystemWatcher.

Now all I have to do is figure out how to (whether) it can be used to watch a subtree and not just a target directory. 

Eram Herman also posted his solution in the NI Example Code repository here.
 
What a relief!

Hopefully I'll figure out how to watch a subtree, when I do, I'll post code on this thread.

Cheers,
Victor
0 Kudos
Message 2 of 5
(3,980 Views)


Wensu wrote:
Hi all,
I'm trying to make a Watched Folder program using the Windows API function ReadDirectoryChangesW.
Attached is a test program which uses CreateFileA to open a handle to a directory, passes the handle to ReadDirectoryChangesW which waits for a change in the directory, and then closes the handle with CloseHandle.

The test performs correctly, in that a handle is created and ReadDirectoryChangesW does wait for a change to the watched path, but I can't get any information about the change from the File_Notify_Information structure that is supposed to contain the changed path.

If we can get this working, it could serve as a good example for how to configure Call Library Function Node for more complex API's. 
I think I'm close, but I haven't been able to sort out the finer points of passing structs from LV to Windows API functions.

Can you see what I'm doing wrong?


There was quite a bit wrong with it. I fixed it and cleaned it up but didn't test anything so far.
 
Rolf Kalbermatter
Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 3 of 5
(3,970 Views)
Hello Rolf,
Thank you for your effort in implementing this function.  I see that my understanding of how to prepare the File_Notify_Information buffer was flawed.   Your solution for reading out the content of this buffer will take some study. 

Gratefully,
Victor
0 Kudos
Message 4 of 5
(3,963 Views)
Hi Rolf,
The code works beautifully.  Though I noticed that a decrement by 1 out of WideCharToMultiByte was causing the last character of the pathname to be omitted.  Removing the decrement resulted in the entire pathname being returned.

Thanks again,
Victor
0 Kudos
Message 5 of 5
(3,959 Views)