Re: Win32 API call ReadConsoleOutput

Tech-Archive recommends: Fix windows errors by optimizing your registry



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);
> }

.



Relevant Pages

  • Win32 API call ReadConsoleOutput
    ... I have noticed that the Win32 API call ReadConsoleOutput fails (returns ... whose columns x rows product exceeds about 13,300 characters. ... accurately communicating the size of this buffer to ReadConsoleOutput. ... AreaHeight, AreaWidth*AreaHeight); ...
    (microsoft.public.win32.programmer.kernel)
  • [PATCH] PRINTK: Decouple input locking from output locking and move render outside lock
    ... ring buffer, and move the render and processing (log level token ... read out to be fed to the console drivers. ... Instead of a single render buffer, vprintkhas two render buffers per ... static int console_locked, console_suspended; ...
    (Linux-Kernel)
  • [UNIX] wu-ftpd fb_realpath() Off-by-One Bug
    ... Wu-ftpd FTP server contains remotely exploitable off-by-one bug. ... characters while the size of the buffer is MAXPATHLEN characters only. ... Following FTP commands may be used to cause buffer overflow: ...
    (Securiteam)
  • Re: Serial Port CE_OVERRUN errors
    ... SerialNG component. ... The main Input buffer is set to 32000, and I have a variable which is ... updated with the maximum number of characters waiting there each time the ... I tried boosting the baud rate from 57.6k to 115.2k, ...
    (comp.lang.pascal.delphi.misc)
  • Re: WaitCommEvent and ResetEvent for SerialPort
    ... This is extremely true when you say you are exhausting the input buffer, ... This receiver thread will then signal your main ... >> From the WaitCommEvent documentation, ... Since no characters are currently coming it, ...
    (microsoft.public.win32.programmer.kernel)