[API]
GetFileSize
ReadFile
SetFilePointer

[INCLUDE]
CreateFile

[DEFINE]
Private FileApi_CurPosPtr As Long
Private FileApi_CurData As String

[CODE]
Public Function TxtFile_ReadOpen(ByVal Filename As String) As Boolean
  Dim xLong1 As Long
  Dim xLong2 As Long
  Dim xLong3 As Long

  xLong1 = CreateFile(Filename, OpenExisting, FILE_READ)
  If Not xLong1 = -1& Then
    xLong2 = GetFileSize(xLong1, xLong3)
    If xLong3 = 0& And xLong2 < &H4000000 And Not xLong2 = 0& Then
      If Not ReadFile(xLong1, ByVal VarPtr(xLong3), 2&, 0&, 0&) = 0& Then
        If (xLong3 And &HFFFF&) = &HFEFF& Then
          If xLong2 Mod 2& = 0& Then
            xLong2 = xLong2 - 2&
            FileApi_CurData = String(xLong2 \ 2&, vbNullChar) + vbCrLf
            If Not ReadFile(xLong1, ByVal StrPtr(FileApi_CurData), xLong2, xLong3, 0&) = 0& Then
              If xLong2 = xLong3 Then
                FileApi_CurPosPtr = 1&
                TxtFile_ReadOpen = True
                End If
              End If
            End If
          ElseIf Not SetFilePointer(xLong1, 0&, 0&, 0&) = -1& Then
          FileApi_CurData = String(xLong2, vbNullChar) + vbCrLf
          If Not ReadFile(xLong1, ByVal FileApi_CurData, xLong2, xLong3, 0&) = 0& Then
            If xLong2 = xLong3 Then
              FileApi_CurPosPtr = 1&
              TxtFile_ReadOpen = True
              End If
            End If
          End If
        End If
      End If
    Call CloseHandle(xLong1)
    End If
  End Function

Public Function TxtFile_ReadLine(ByRef xLine As String) As Boolean
  Dim xLong1 As Long
  
  xLong1 = InStr(FileApi_CurPosPtr, FileApi_CurData, vbCrLf)
  If Not xLong1 = 0& Then
    xLine = Mid(FileApi_CurData, FileApi_CurPosPtr, xLong1 - FileApi_CurPosPtr)
    FileApi_CurPosPtr = xLong1 + 2&
    TxtFile_ReadLine = True
    End If
  End Function

Public Sub TxtFile_ReadClose()
  FileApi_CurData = ""
  End Sub
