🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.nativeapi
5 messages
5 total messages Started by Rod Tue, 16 May 2006 14:38
ReadDirectoryChangesW
#3668
Author: Rod
Date: Tue, 16 May 2006 14:38
24 lines
1552 bytes
Hello.

Would anyone be able to give me some (short) sample code showing how to use
the "ReadDirectoryChangesW" function (in "synchronous" mode.) I want to
monitor a single directory. There won't be many changes,in any given day,
to the directory being monitored.

My main lack of understanding lies with:

LPVOID lpBuffer,     // pointer to the buffer to receive the read results
DWORD nBufferLength, // length of lpBuffer


Thanks for any help.

Regards,

Rod.

-- Rod

Please note that, due to time differences etc, it might be 24hrs before I
get back to this group so please consider yourselves thanked for any help
you may be able to provide.
Re: ReadDirectoryChangesW
#3670
Author: Andrue Cope [TeamB]
Date: Tue, 16 May 2006 15:05
23 lines
1518 bytes
Rod wrote:

> My main lack of understanding lies with:
> 
> LPVOID lpBuffer,     // pointer to the buffer to receive the read
> results DWORD nBufferLength, // length of lpBuffer

I think you might need to describe your problem further. The above is
(I assume) blatantly obvious since the two variables are describing an
area of memory where something can be written.

Are you confused about the format of the data that will be written
there?

The following link (obtained by Googling for 'ReadDirectoryChangesW')
may be useful:

http://www.codeproject.com/file/directorychangewatcher.asp

-- 
Andrue Cope [TeamB]
[Bicester, Uk]
http://info.borland.com/newsgroups/guide.html
Re: ReadDirectoryChangesW
#3676
Author: Rod
Date: Wed, 17 May 2006 14:14
93 lines
3667 bytes
"Andrue Cope [TeamB]" <no.spam@not.a.valid.address> wrote:

Andrue,
       I don't know what was going through my head!!!

The "buffer" and buffer length were NOT the issue.

I have code which works "synchronously" which isn't ideal. 

How do I implement the function "ReadDirectoryChangesW" asynchronously?

(Reference:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/fs/readdirectorychangesw.asp
)

MSDN says there are three ways to do it:
(1) GetOverlappedResult
(2) GetQueuedCompletionStatus using "CreateIoCompletionPort".
(3) Using a completion routine.

I don't know how to implement any of them.

Below is what I'm doing at the moment.

  char *chFile1 = "C:\\TMP1";
  DWORD dwBytesReturned = 0;
  FILE_NOTIFY_INFORMATION fni[1024];
  HANDLE hDir;

    hDir = CreateFile (chFile1, // pointer to the file name
              FILE_LIST_DIRECTORY,  // access mode
              FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
              NULL,                               // security descriptor
              OPEN_EXISTING,                      // how to create
              FILE_FLAG_BACKUP_SEMANTICS,         // file attributes
              NULL                                
            );

    if (hDir == INVALID_HANDLE_VALUE)
    {
       .... handle error and exit.
    }


    while(1)
    { //Non zero if function succeeds.
     Sleep(2000);
     if(!ReadDirectoryChangesW( hDir,&fni[0],
(sizeof(FILE_NOTIFY_INFORMATION) * 1024),
FALSE, FILE_NOTIFY_CHANGE_FILE_NAME|FILE_NOTIFY_CHANGE_LAST_WRITE,
&dwBytesReturned,  NULL, NULL ))
      {
        .... handle error and exit.
        break;
      }
      else
      {
       .... handle returned data.
      }
    }//End of while.

=================end code snippet==========================

If you can get me over the line I'd be most grateful.

Regards,

Rod.

:>Rod wrote:
:>
:>> My main lack of understanding lies with:
:>> 
:>> LPVOID lpBuffer,     // pointer to the buffer to receive the read
:>> results DWORD nBufferLength, // length of lpBuffer
:>
:>I think you might need to describe your problem further. The above is
:>(I assume) blatantly obvious since the two variables are describing an
:>area of memory where something can be written.
:>
:>Are you confused about the format of the data that will be written
:>there?
:>
:>The following link (obtained by Googling for 'ReadDirectoryChangesW')
:>may be useful:
:>
:>http://www.codeproject.com/file/directorychangewatcher.asp

-- Rod

Please note that, due to time differences etc, it might be 24hrs before I
get back to this group so please consider yourselves thanked for any help
you may be able to provide.
Re: ReadDirectoryChangesW
#3680
Author: JD
Date: Thu, 18 May 2006 10:57
33 lines
2152 bytes
Rod <notat022005@end.of.msg> wrote:
>
> [...] How do I implement the function ReadDirectoryChangesW
> asynchronously?

Have you looked at the win32 API FindFirstChangeNotification?

//-------------------------------------------------------------
void __fastcall TMonitorThread::Execute()
{
    int Counter = 0;
    HANDLE hFind = FindFirstChangeNotification(FPath.c_str(), false, FILE_NOTIFY_CHANGE_LAST_WRITE);
    if( hFind != INVALID_HANDLE_VALUE )
      {
          while( !Terminated )
            {
                switch( WaitForSingleObject(hFind, 500) )
                  {
                      case WAIT_OBJECT_0: ++Counter;
                                          ::SendMessage(Application->MainForm->Handle, APP_FILECHANGE_NOTIFICATION, Counter, 0 );
                                          if( !FindNextChangeNotification(hFind) ) Terminate();
                                          break;
                      case  WAIT_TIMEOUT: break;
                      default           : Terminate();
                  }
            }
          FindCloseChangeNotification(hFind);
      }
}
//-------------------------------------------------------------

~ JD
Re: ReadDirectoryChangesW
#3681
Author: Rod
Date: Thu, 18 May 2006 13:01
39 lines
2387 bytes
"JD" <nospam@nospam.com> wrote:
Hello JD.

Yes, I've implemented a version of the program using
"FindFirstChangeNotification" and the " FindNextChangeNotification".
However, these report only that the type of change being monitored has
occurred but not which files underwent that change. Therefore, I have to
keep the relevant data about the files in memory and iterate through both
the directory and that list till I find either new file(s) or altered
files.

Whereas "ReadDirectoryChangesW" reports which files have changed and what
the change is. It seems much better suited for the job at hand.

All the examples I have looked at are in quite complicated projects which
obscures the basic functionality.

If someone could get me started on the "asynchronously" use of
"ReadDirectoryChangesW" I'd merrily on my way, I believe.

Regards,

Rod.

:>
:>Rod <notat022005@end.of.msg> wrote:
:>>
:>> [...] How do I implement the function ReadDirectoryChangesW
:>> asynchronously?
:>
:>Have you looked at the win32 API FindFirstChangeNotification?
:>
:>//-------------------------------------------------------------

-- Rod

Please note that, due to time differences etc, it might be 24hrs before I
get back to this group so please consider yourselves thanked for any help
you may be able to provide.
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads