gpt4 book ai didi

c++ - 使用 CeGetFileNotificationInfo

转载 作者:太空宇宙 更新时间:2023-11-04 14:26:17 26 4
gpt4 key购买 nike

我有一个 Windows Mobile 6.5 应用程序,我试图在其中监视文件的更改。如果我运行下面的代码,然后打开写字板并编辑并保存“\MyDir\Foo.txt”,我只会收到有关临时文件被更改的通知。

作为引用,我使用的是 Windows Mobile 6.5 Professional CE OS 5.2.23090.5.3.0。而且,我对 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;
}

我上面给出的例子中的输出是:

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

我期望的位置:

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

我需要更改什么才能获得我正在寻找的功能?

谢谢,保罗H

最佳答案

来自 MSDN:

For an OS that uses extensive caching, detection occurs only when the cache is sufficiently flushed.

更多信息:https://msdn.microsoft.com/en-US/library/ee490599(v=winembedded.60).aspx

关于c++ - 使用 CeGetFileNotificationInfo,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3755210/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com