// © 1997-2008 by FNS Enterprize's (FNSE.de)
// © 2003-2008 by himitsu @ Delphi-PRAXiS.de
Function CreateTempFileA(lpPrefixString: LPSTR; bShareRead: Boolean = False; TempFileName: PFileNameA =
nil):
HANDLE;
{not Inline}
Const RM:
Array[Boolean]
of DWORD = (FILE_SHARE_READ, 0);
Var i: Integer;
S, S2: TFileNameA;
E: LongInt;
Begin
Result := INVALID_HANDLE_VALUE;
If GetTempPathA(MAX_PATH, @S) > MAX_PATH
Then Exit;
i := 9999;
Repeat
If GetTempFileNameA(@S, lpPrefixString, 0, @S2) = 0
Then Exit;
Result := CreateFileA(@S2, GENERIC_READ
or GENERIC_WRITE, RM[bShareRead],
nil, CREATE_NEW, FILE_ATTRIBUTE_TEMPORARY
or FILE_FLAG_DELETE_ON_CLOSE, 0);
If Result = INVALID_HANDLE_VALUE
Then Begin
E := GetLastError;
SetLastError(E);
End Else E := 0;
Dec(i);
Until (i = 0)
or (E <> ERROR_ALREADY_EXISTS);
If TempFileName <>
nil Then TempFileName^ := S2;
End;