🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #13966

Re: How to spy on a console's screen buffer?

#13966
From: Bob Gonder
Date: Sun, 31 Aug 2003 21:42
29 lines
2302 bytes
Sean McCune wrote:

>I'm trying to write an application that accesses the screen buffers of
>console apps to read what is currently visible in the console app's window.
>The pseudo-code is below.  I know it doesn't have error checking.  The real
>code does.  I ripped out all of the extraneous stuff.
>
>At any rate, the code below works when run in the debugger.
>
>   hwnd = FindWindow( className, title );
>   GetWindowThreadProcessId( hwnd, &pid );
>   AttachConsole( pid );
>   out = GetStdHandle( STD_OUTPUT_HANDLE );
>   result = ReadConsoleOutputCharacter( out, internalBuf, length, c,
>nRead );
>
>When run in the debugger, the buffer internalBuf gets filled with the text
>from the console app's window.  When run outside the debugger, result is
>always false and the error is ERROR_INVALID_HANDLE.  

First (in case others didn't know) AttachConsole() is new to XP. If
your system is older, it might not work.

Next, make sure hwnd is not NULL.
Then make sure pidl is valid.
Then make sure AttachConsole() returns TRUE.
Then, I believe  sizeof(internalBuf) should be 2*length.
Lastly, make sure nRead is an address and not a value (usually
&nRead).
Technical Details
Message-ID: <18q4lvgpblacuoi16db0itri3gm1j171p7@4ax.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-03!sn-xit-04!sn-xit-01!sn-xit-05!sn-xit-09!supernews.com!newsfeed.news2me.com!newsfeed.media.kyoto-u.ac.jp!newsfeed.gol.com!news-hog.berkeley.edu!ucberkeley!nntp-relay.ihug.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
References: <3f5247ae@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10cc67,e59457b0353e4c0f
X-Google-Attributes: gid10cc67,public
X-Google-ArrivalTime: 2003-08-31 14:56:06 PST
From: Bob Gonder <notbg@notmindspring.invalid>
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: Re: How to spy on a console's screen buffer?
Date: Sun, 31 Aug 2003 14:42:06 -0700
Organization: MindSpring Enterprises, Inc.
Reply-To: notbg@notmindspring.invalid
Message-ID: <18q4lvgpblacuoi16db0itri3gm1j171p7@4ax.com>
References: <3f5247ae@newsgroups.borland.com>
X-Newsreader: Forte Agent 1.91/32.564
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 64.158.104.31
X-Trace: newsgroups.borland.com 1062366133 64.158.104.31 (31 Aug 2003 14:42:13 -0700)
Lines: 31
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-03!sn-xit-04!sn-xit-01!sn-xit-05!sn-xit-09!supernews.com!newsfeed.news2me.com!newsfeed.media.kyoto-u.ac.jp!newsfeed.gol.com!news-hog.berkeley.edu!ucberkeley!nntp-relay.ihug.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail