日志_测试代码_Delphi7

1、

2、Delphi (Windows API 文件尾部添加)

function LogFile(_str :string) :integer;
var hFile :THandle;
    strFileName :string;
    dwWritten :DWORD;
    lb :LongBool;
begin
  Result := 0;
  strFileName := ParamStr(0)+'.'+FormatDateTime('yyyymmdd', now)+'.log';
  hFile := CreateFile(PChar(strFileName), GENERIC_WRITE, FILE_SHARE_READ, 0, CREATE_NEW, 0, 0);
  if (hFile = INVALID_HANDLE_VALUE) then
  begin
    Result := GetLastError;
    Exit;
  end;
  lb := Windows.SetEndOfFile(hFile);
  if (not lb) then
  begin
    Result := GetLastError;
    CloseHandle(hFile);
    Exit;
  end;
  dwWritten := 0;
  lb := Windows.WriteFile(hFile, _str[1], Length(_str), dwWritten, nil);
  if (not lb) then
  begin
    Result := GetLastError;
    CloseHandle(hFile);
    Exit;
  end;
  CloseHandle(hFile);
end;

 

3、

 

posted @ 2016-12-02 10:17  CppSkill  阅读(246)  评论(0编辑  收藏  举报