I have noticed that notepad can take a very long time to load a large where it appears to be completely unresponsive but the file handle only seems to be active for a very short period of time during the beginning. Once the loading has begun another process can open a file for exclusive share mode, ie using the value 0 for dwShareMode

How does notepad continue to do it's loading with a closed handle or whatever magic it uses?

有帮助吗?

解决方案

Nevermind I have figured out what notepad does. Here's the sollution if anyone else needs it:

hFile = CreateFile("file", 0x80000000, 3, NULL, 3, 0x80, NULL);
hMap = CreateFileMapping(hFile, NULL, 2, sizeHigh, sizeLow, NULL);
ptr = MapViewOfFile(hMap, 4, 0, 0, size);
CloseHandle(hMap);
CloseHandle(hFile);

/* At this point the handles are closed so programs that try
   to get share exclusive on the file succeed but I still have
   a pointer for reading the memory myself */ 

UnmapViewOfFile(ptr);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top