Re: Win32 API call ReadConsoleOutput
- From: "Gary Chanson" <gjchanson@xxxxxxxxxxxxxxxxxxxx>
- Date: Sat, 10 Dec 2005 16:45:05 -0500
Could it be that the console is only 132 x 300? That would see a limit on
how much you can read regardless of the size of the buffer you supply.
--
-GJC [MS Windows SDK MVP]
-Software Consultant (Embedded systems and Real Time Controls)
- http://www.mvps.org/ArcaneIncantations/consulting.htm
-gchanson@xxxxxxxx
"Rich Pasco" <richp1234@xxxxxxxxxxx> wrote in message
news:439B30FD.2050907@xxxxxxxxxxxxxx
> 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.
> The command-line "net helpmsg 8" returns "Not enough storage is
> available to process this command."
>
> It would certainly seem that I am allocating a large enough buffer
> for 132 x 300 = 39600 characters, nearly (but not exactly) three
> times the threshold where ReadConsoleOutput fails. And I believe I am
> accurately communicating the size of this buffer to ReadConsoleOutput.
>
> Below is the full source code and executable for the program making
> this determination.
>
> Known to work with 13298 characters
> Known to fail with 13310 characters
>
> Can anyone say why 13300 is the cause of so much trouble?
>
> - Rich
>
> /*
> Run this program in a console buffer of 300 lines of 132 characters each
> for various values of width (at most than 132) and height (at most 300).
> */
>
> #include "windows.h"
> #include "stdlib.h"
> #include "stdio.h"
>
> void main(int argc, char*argv[]) {
>
> // Misc Stuff
> long err;
> COORD cZeroZero = {0,0};
>
> // My Buffer
> void* pBuffer;
> short sBufWidth = 132;
> short sBufHeight = 300;
> long lBufSize = (long)sBufWidth*(long)sBufHeight*sizeof(CHAR_INFO);
> COORD cBufShape = {sBufWidth, sBufHeight};
>
> // My Area
> short AreaWidth, AreaHeight;
> SMALL_RECT srArea;
>
> // The Console
> HANDLE hMyConsole = GetStdHandle(STD_OUTPUT_HANDLE);
>
> if (argc != 3) {
> printf("Usage: copys width height\n");
> exit(EXIT_SUCCESS);
> }
> sscanf(argv[1],"%ld",&AreaWidth);
> sscanf(argv[2],"%ld",&AreaHeight);
>
> srArea.Left = 0;
> srArea.Top = 0;
> srArea.Right = AreaWidth-1;
> srArea.Bottom = AreaHeight-1;
>
> printf("Area requested: %d x %d = %ld characters\n", AreaWidth,
> AreaHeight, (long)AreaWidth*(long)AreaHeight);
>
> 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
> cZeroZero, // to top left of buffer
> &srArea) // rectangle being read
> ) {
> err = GetLastError();
> printf("ReadConsoleOutput failed: %ld\n", err);
> exit(EXIT_FAILURE);
> }
>
> printf("ReadConsoleOutput succeeded!\n");
> printf("Area read:
> (%d,%d)-(%d,%d)\n",srArea.Left,srArea.Top,srArea.Right,srArea.Bottom);
> exit(EXIT_SUCCESS);
> }
.
- Follow-Ups:
- Re: Win32 API call ReadConsoleOutput
- From: Rich Pasco
- Re: Win32 API call ReadConsoleOutput
- From: Rich Pasco
- Re: Win32 API call ReadConsoleOutput
- References:
- Win32 API call ReadConsoleOutput
- From: Rich Pasco
- Win32 API call ReadConsoleOutput
- Prev by Date: Win32 API call ReadConsoleOutput
- Next by Date: Re: DebugActiveProcessStop()
- Previous by thread: Win32 API call ReadConsoleOutput
- Next by thread: Re: Win32 API call ReadConsoleOutput
- Index(es):
Relevant Pages
|