🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #3676

Re: ReadDirectoryChangesW

#3676
From: 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.
Technical Details
Message-ID: <gubm62dc961n3brhgmkmm6ptpc3o4oob5f@4ax.com>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!news4.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
References: <btnj629qq4hcqg2rm80fr6mdo9d1uv7ida@4ax.com> <4469ea36@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,f9b15488efc2a992
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: Rod <notat022005@end.of.msg>
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: Re: ReadDirectoryChangesW
Date: Thu, 18 May 2006 00:14:41 +1000
Reply-To: sorrynothere@end.of.message
Message-ID: <gubm62dc961n3brhgmkmm6ptpc3o4oob5f@4ax.com>
References: <btnj629qq4hcqg2rm80fr6mdo9d1uv7ida@4ax.com> <4469ea36@newsgroups.borland.com>
X-Newsreader: Forte Agent 1.93/32.576 English (American)
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 203.217.84.246
X-Trace: newsgroups.borland.com 1147875107 203.217.84.246 (17 May 2006 07:11:47 -0700)
Lines: 93
Path: arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!news4.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail