[INCLUDE]
TxtFile_ReadOpenEx
TxtFile_WriteCreateEx
GetFileAttributes

[CODE]
Public Function TxtFile_WriteAppendEx(ByVal Filename As String, ByVal DefaultEncoding As TxtFile_EncodingEnum, ByVal DefaultByteOrderMark As Boolean) As Long
  Dim xType1 As TxtFileWriteStruct
  
  xType1.hFile = TxtFile_ReadOpenEx(Filename, xType1.Encoding, 0&, True)
  If xType1.hFile = -1& Then
    If GetFileAttributes(Filename) = -1& Then
      TxtFile_WriteAppendEx = TxtFile_WriteCreateEx(Filename, DefaultEncoding, DefaultByteOrderMark)
      End If
    Else
    TxtFile_WriteAppendEx = LocalAlloc(0&, TxtFileWriteStructLen)
    If Not TxtFile_WriteAppendEx = 0& Then
      Call RtlMoveMemory(ByVal TxtFile_WriteAppendEx, xType1, TxtFileWriteStructLen)
      GoTo Success
      End If
    Call CloseHandle(xType1.hFile)
    End If
Success:
  End Function
