views:

16

answers:

0

I have a Windows Mobile 6.5 application where I'm trying to monitor a file for changes. If I run the code below, then open WordPad and edit and save "\MyDir\Foo.txt", I only get notifications about temporary files being changed.

For reference, I'm using Windows Mobile 6.5 Professional CE OS 5.2.23090.5.3.0. And, I have the same issue with Windows Mobile 6.1 Professional CE OS 5.2.21051.1.6.4.

#include <vector>

int _tmain( int argc, _TCHAR* argv[] )
{
    HANDLE change = ::FindFirstChangeNotification( 
        argv[ 1 ],
        FALSE,
        FILE_NOTIFY_CHANGE_CEGETINFO |
        FILE_NOTIFY_CHANGE_LAST_WRITE |
        FILE_NOTIFY_CHANGE_LAST_ACCESS |
        FILE_NOTIFY_CHANGE_CREATION |
        FILE_NOTIFY_CHANGE_ATTRIBUTES |
        FILE_NOTIFY_CHANGE_SIZE );

    if( INVALID_HANDLE_VALUE != change )
    {
        while( WAIT_OBJECT_0 == ::WaitForSingleObject( change, INFINITE ) )
        {
            NKDbgPrintfW( L"Change detected\n" );
            DWORD returned = 0;
            DWORD available = 0;
            if( ::CeGetFileNotificationInfo( change,
                                             0,
                                             NULL,
                                             0,
                                             &returned,
                                             &available ) )
            {
                std::vector< BYTE > buffer( available );
                if( ::CeGetFileNotificationInfo( change,
                                                 0,
                                                 &buffer.front(),
                                                 buffer.size(),
                                                 &returned,
                                                 &available ) )
                {
                    BYTE* current = &buffer.front();

                    const FILE_NOTIFY_INFORMATION* info =
                    reinterpret_cast< const FILE_NOTIFY_INFORMATION* >( current );

                    for( current;
                         NULL != current && info->NextEntryOffset > 0;
                         current += info->NextEntryOffset )
                    {
                        info = reinterpret_cast< const FILE_NOTIFY_INFORMATION* >( current );  
                        NKDbgPrintfW( L"\t%s: %#08x\n", info->FileName, info->Action );
                    }

                }
            }      
            ::FindNextChangeNotification( change );
        }
        ::FindCloseChangeNotification( change );
    }
    return 0;
}

The output in the example I give above is:

Change detected
    667F.tmp: 0x00000003
    667F.tmp: 0x00000003
    667F.tmp: 0x00000003
    667F.tmp: 0x00010000

Where I would expect it to be:

Change detected
    Foo.txt: 0x00000003
    Foo.txt: 0x00000003
    Foo.txt: 0x00000003
    Foo.txt: 0x00010000

What do I need to change to get the functionality I'm looking for?

Thanks, PaulH