ericqliu

路在奋斗者的脚下延伸......

  博客园 :: 首页 :: 新随笔 :: 联系 :: 订阅 :: 管理 ::

Option Explicit
Private Const GENERIC_WRITE_E = &H40000000
Private Const FILE_SHARE_READ_E = &H1
Private Const FILE_SHARE_WRITE_E = &H2
Private Const INVALID_HANDLE_VALUE_E As Long = -1
Private Const FILE_BEGIN_E = 0

Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, lpSecurityAttributes As Long, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
Private Declare Function GetFileSize Lib "kernel32" (ByVal hFile As Long, lpFileSizeHigh As Long) As Long
Private Declare Function SetFilePointer Lib "kernel32" (ByVal hFile As Long, ByVal lDistanceToMove As Long, lpDistanceToMoveHigh As Long, ByVal dwMoveMethod As Long) As Long
Private Declare Function WriteFile Lib "kernel32" (ByVal hFile As Long, lpBuffer As Any, ByVal nNumberOfBytesToWrite As Long, lpNumberOfBytesWritten As Long, ByVal lpOverlapped As Any) As Long
Public Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long

Public Function WriteLogT(ByVal strLogFile As String, ByVal strMsg As String, Optional blnForceCreate As Boolean = False) As Boolean

    Dim hFile As Long
    Dim lngSize As Long
    Dim lngRet As Long
    Dim bytBuffer() As Byte
    Dim lngCreateDis As Long
   
    lngCreateDis = 4
    hFile = CreateFile(strLogFile, GENERIC_WRITE_E, FILE_SHARE_READ_E Or FILE_SHARE_WRITE_E, ByVal 0&, lngCreateDis, 0, 0)
    If hFile <> INVALID_HANDLE_VALUE_E Then
        lngSize = GetFileSize(hFile, 0)
        If lngSize > 0 Then
            SetFilePointer hFile, lngSize, 0, FILE_BEGIN_E
        End If
        bytBuffer = StrConv(strMsg, vbFromUnicode)
        If UBound(bytBuffer) > 0 Then
            WriteFile hFile, bytBuffer(0), UBound(bytBuffer) + 1, lngRet, ByVal 0&
        End If
        WriteFile hFile, 13, 1, lngRet, ByVal 0&
        WriteFile hFile, 10, 1, lngRet, ByVal 0&
        CloseHandle hFile
        WriteLogT = True
    End If
End Function

posted on 2005-07-22 08:41  ericqliu  阅读(244)  评论(0)    收藏  举报