[API]
CONSOLE_SCREEN_BUFFER_INFO
GetStdHandle
GetConsoleScreenBufferInfo
ReadConsoleOutputCharacterW
ReadConsoleOutputCharacterA
GetConsoleOutputCP

[INCLUDE]
Unicode
CPDecode

[CODE]
Public Function GetConsoleOutput_Raw(Optional ByRef NumCharsX As Long) As String
  Dim xLong1 As Long
  Dim xLong2 As Long
  Dim xType1 As CONSOLE_SCREEN_BUFFER_INFO

  xLong1 = GetStdHandle(-11&)
  If Not xLong1 = -1& Then
    If Not GetConsoleScreenBufferInfo(xLong1, xType1) = 0& Then
      NumCharsX = xType1.dwSize.x
      GetConsoleOutput_Raw = String(NumCharsX * xType1.dwSize.y, vbNullChar)
      If IsUnicode Then
        If Not ReadConsoleOutputCharacterW(xLong1, StrPtr(GetConsoleOutput_Raw), xType1.dwSize.x * xType1.dwSize.y, 0&, xLong2) = 0& Then
          If xLong2 = NumCharsX * xType1.dwSize.y Then
            GoTo Success
            End If
          End If
        Else
        If Not ReadConsoleOutputCharacterA(xLong1, GetConsoleOutput_Raw, xType1.dwSize.x * xType1.dwSize.y, 0&, xLong2) = 0& Then
          If xLong2 = NumCharsX * xType1.dwSize.y Then
            GetConsoleOutput_Raw = CPDecode(GetConsoleOutputCP, GetConsoleOutput_Raw)
            GoTo Success
            End If
          End If
        End If
      End If
    End If
  GetConsoleOutput_Raw = ""
Success:
  End Function
