Private Const GENERIC_WRITE = &H40000000
Private Const FILE_SHARE_READ = &H1
Private Const FILE_SHARE_WRITE = &H2
Private Const INVALID_HANDLE_VALUE As Long = -1
Private Const FILE_BEGIN = 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 WriteLog(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, FILE_SHARE_READ Or FILE_SHARE_WRITE, ByVal 0&, lngCreateDis, 0, 0)
If hFile <> INVALID_HANDLE_VALUE Then
lngSize = GetFileSize(hFile, 0)
If lngSize > 0 Then
SetFilePointer hFile, lngSize, 0, FILE_BEGIN
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
WriteLog = True
End If
End Function