Win32 API call ReadConsoleOutput

  • Thread starter Thread starter Rich Pasco
  • Start date Start date
R

Rich Pasco

I couldn't find a newsgroup for the Win32 API calls, so I hope I get
an answer here.

I have noticed that the Win32 API call ReadConsoleOutput fails (returns
false) whenever its last parameter psrctSourceRect defines a rectangle
whose columns x rows product exceeds about 13,300 characters. This
is true even if the allocation of the pchiDestBuffer (specified in
coordDestBufferSize) is very large.

When it fails (returns false) the function GetLastError returns 8, but I
could not find an explanation of what that means.

Known to work with 13298
Known to fail with 13310

Attached is the full source code and executable for the program making
this determination.

Can anyone say why 13300 is the cause of so much trouble?

- Rich
 
C:\Program Files\Support Tools>net helpmsg 8

Not enough storage is available to process this command.
 
Rich Pasco said:
I couldn't find a newsgroup for the Win32 API calls, so I hope I get
an answer here.

I have noticed that the Win32 API call ReadConsoleOutput fails (returns
false) whenever its last parameter psrctSourceRect defines a rectangle
whose columns x rows product exceeds about 13,300 characters. This
is true even if the allocation of the pchiDestBuffer (specified in
coordDestBufferSize) is very large.

This really isn't the right newsgroup for API questions. One of the
microsoft.public.vc.* groups would be better.
 
David said:
C:\Program Files\Support Tools>net helpmsg 8

Not enough storage is available to process this command.

David, thank you for showing me how to understand the error code
returned by GetLastError, but I don't understand how there could
be not enough storage. I successfully allocate a large enough
buffer just before calling ReadConsoleOutput, and pass the buffer
information to it. My code includes...

void* pBuffer;
short sBufWidth = 132;
short sBufHeight = 300;
long lBufSize = (long)sBufWidth*(long)sBufHeight*sizeof(CHAR_INFO);
COORD coordZeroZero = {0,0};
COORD cBufShape = {sBufWidth, sBufHeight};
...
pBuffer = malloc(lBufSize);
if (!pBuffer) {
printf("GetMem failed.\n");;
exit(EXIT_FAILURE);
}

if (!ReadConsoleOutput(
hMyConsole, // from my console buffer
pBuffer, // to my memory buffer
cBufShape, // column-row size of memory buffer
coordZeroZero, // to top left of buffer
&srArea) // rectangle being read
) {
err = GetLastError();
printf("ReadConsoleOutput failed: %ld\n", err);
exit(EXIT_FAILURE);
}

The "malloc" succeeds, but the ReadConsoleOutput fails when
srArea defines a rectangle smaller than 132 x 300 (in fact,
any rectangle whose area exceeds about 13300 characters).

BTW I am running my application on a machine with over 1 GB of physical
memory, and enough disk space for a much larger virtual memory.

- Rich
 
Back
Top