0
votes

the code:

#include <windows.h>
#include <stdio.h>
int main() {
  system("mode 128");
  int range = 0xCFE2;
  char* buf = new char[range+1];
  DWORD dwChars;
  if (!ReadConsoleOutputCharacter(
    GetStdHandle(STD_OUTPUT_HANDLE),
    buf,  // Buffer where store symbols
    range,     // Read len chars
    {0,0},    // Read from row=8, column=6
    &dwChars // How many symbols stored
  )) {
    printf("GetLastError: %lu\n", GetLastError());
  }
  system("pause");
  return 0;
}
2

2 Answers

4
votes

Console screen buffers cannot be larger than 64K. Each character in the buffer requires 2 bytes, one for the character code and another for the color attributes. It therefore never makes any sense to try to read more than 32K chars with ReadConsoleOutputCharacter().

You don't have a real problem.

1
votes

The documentation for WriteConsole() says:

If the total size of the specified number of characters exceeds the available heap, the function fails with ERROR_NOT_ENOUGH_MEMORY.

ReadConsoleOutputCharacter() probably has a similar restriction if you try to read too much, even though it is not documented. Try using GetConsoleScreenBufferInfo() or similar function to determine how many rows and columns there are, and then don't read more than that.