Registriert seit: 29. Mai 2002
37.621 Beiträge
Delphi 2006 Professional
|
Re: Festplattenzugriffe
9. Mär 2006, 10:24
Hallo Christian. Ich habe es jetzt so:
Delphi-Quellcode:
procedure TcsDirThread.Execute;
var
pBuf : Pointer;
pWork : Pointer;
dwBufLen : DWORD;
dwDummy : DWORD;
sResult : string;
FNI : FILE_NOTIFY_INFORMATION;
dwRead : DWORD;
dwKey : DWORD;
pOVL : POVERLAPPED;
iCopyLen : integer; // Prevent Buffer Overflow
begin
// Normalerweise im Konstruktor erzeugt
FhFile := CreateFile(PChar(FsDirPath), FILE_LIST_DIRECTORY, FILE_SHARE_READ or FILE_SHARE_DELETE or FILE_SHARE_WRITE, nil,
OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS or FILE_FLAG_OVERLAPPED, 0);
FhComPort := CreateIoCompletionPort(FhFile, 0, $1234ABCD, 0);
FillChar(Fovl, SizeOf(Fovl), 0);
// Execute
pOVL := @Fovl;
dwBufLen := 65536;
GetMem(pBuf, dwBufLen);
try
while not Terminated do
begin
ZeroMemory(pBuf, dwBufLen);
if not ReadDirectoryChangesW(FhFile, pBuf, dwBufLen, true, FILE_NOTIFY_CHANGE_LAST_WRITE, @dwDummy, @Fovl, nil)
then
Terminate;
if Terminated then
break;
if not GetQueuedCompletionStatus(FhComPort, dwRead, dwKey, pOVL, INFINITE) then
begin
Terminate;
end
else
begin
if Terminated then
break;
pWork := pBuf;
repeat
CopyMemory(@FNI, pWork, 12);
iCopyLen := FNI.dwFileNameLength;
if iCopyLen > _iFilenameLength then
iCopyLen := _iFilenameLength;
CopyMemory(@FNI.wFilename[1], PChar(pWork) + 12, iCopyLen);
PChar(pWork) := PChar(pWork) + FNI.dwNextEntryOffset;
FsReason := GetReason(FNI.dwAction);
if FNI.dwAction = FILE_ACTION_ADDED then
begin
Synchronize(AddReasonToMemo);
Synchronize(AddFileToMemo);
FError := MoveChangedFiles(FFPATH + FsFileName);
if FError <> 0 then
Synchronize(AddErrorToMemo);
end;
until FNI.dwNextEntryOffset = 0;
SetLength(sResult, iCopyLen);
ZeroMemory(@sResult[1], length(sResult));
(*if WideCharToMultiByte(GetACP, WC_NO_BEST_FIT_CHARS, @FNI.wFilename, iCopyLen, @sResult[1], iCopyLen, nil, nil)
<> 0 then
begin
end;*)
end;
end;
finally
FreeMem(pBuf, dwBufLen);
end;
// Destruktor
if (FhFile <> INVALID_HANDLE_VALUE) and (FhFile <> 0) then
CloseHandle(FhFile);
if FhComPort <> 0 then
CloseHandle(FhComPort);
end;
Aber wenn ich debugge und einen Breakpunkt auf die Zeile 42 setze, dann kommt er nie dort an, weil er von GetQueuedCompletionStatus nie zurückkommt.
Michael Ein Teil meines Codes würde euch verunsichern.
|