2010-09-20 1 views
1

J'ai une application Windows Mobile 6.5 où j'essaie de surveiller un fichier pour y apporter des modifications. Si je cours le code ci-dessous, alors ouvrez WordPad et éditez et enregistrez "\ MyDir \ Foo.txt", j'obtiens seulement des notifications au sujet des dossiers provisoires changés.Utilisation de CeGetFileNotificationInfo

Pour référence, j'utilise Windows Mobile 6.5 Professionnel CE OS 5.2.23090.5.3.0. Et, j'ai le même problème avec Windows Mobile 6.1 Professionnel 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; 
} 

La sortie dans l'exemple que je donne ci-dessus est:

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

Où je pensais que ce serait:

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

Que dois-je changer pour obtenir la fonctionnalité I cherche?

Merci, PaulH

+0

Y at-il des changements supplémentaires lorsque vous fermez WordPad? –

+0

@Richard Cook - Lorsque je ferme Word Pad, le fichier est sauvegardé. C'est quand tous les changements ont lieu. – PaulH

Répondre