- Open CONOUT$ for accessing the console buffer. This fixes the

"GetConsolScreenBufferInfo : error 6" message, if the stdout handle is redirected.

svn path=/trunk/; revision=4810
This commit is contained in:
Hartmut Birr 2003-06-01 17:06:22 +00:00
parent f170e40b0a
commit ec5e98348c
5 changed files with 21 additions and 20 deletions

View file

@ -46,17 +46,17 @@ INT cmd_cls (LPTSTR cmd, LPTSTR param)
return 0; return 0;
} }
GetConsoleScreenBufferInfo (hOut, &csbi); GetConsoleScreenBufferInfo (hConsole, &csbi);
coPos.X = 0; coPos.X = 0;
coPos.Y = 0; coPos.Y = 0;
FillConsoleOutputAttribute (hOut, wColor, FillConsoleOutputAttribute (hConsole, wColor,
(csbi.dwSize.X)*(csbi.dwSize.Y), (csbi.dwSize.X)*(csbi.dwSize.Y),
coPos, &dwWritten); coPos, &dwWritten);
FillConsoleOutputCharacter (hOut, _T(' '), FillConsoleOutputCharacter (hConsole, _T(' '),
(csbi.dwSize.X)*(csbi.dwSize.Y), (csbi.dwSize.X)*(csbi.dwSize.Y),
coPos, &dwWritten); coPos, &dwWritten);
SetConsoleCursorPosition (hOut, coPos); SetConsoleCursorPosition (hConsole, coPos);
bIgnoreEcho = TRUE; bIgnoreEcho = TRUE;

View file

@ -1,4 +1,4 @@
/* $Id: cmd.c,v 1.2 2003/04/26 16:38:05 ekohl Exp $ /* $Id: cmd.c,v 1.3 2003/06/01 17:06:22 hbirr Exp $
* *
* CMD.C - command-line interface. * CMD.C - command-line interface.
* *
@ -144,6 +144,7 @@ DWORD dwChildProcessId = 0;
OSVERSIONINFO osvi; OSVERSIONINFO osvi;
HANDLE hIn; HANDLE hIn;
HANDLE hOut; HANDLE hOut;
HANDLE hConsole;
#ifdef INCLUDE_CMD_COLOR #ifdef INCLUDE_CMD_COLOR
WORD wColor; /* current color */ WORD wColor; /* current color */
@ -1163,14 +1164,13 @@ int main (int argc, char *argv[])
SetFileApisToOEM(); SetFileApisToOEM();
AllocConsole(); AllocConsole();
if (GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &Info) == FALSE) hConsole = CreateFile("CONOUT$", GENERIC_READ|GENERIC_WRITE,
FILE_SHARE_READ|FILE_SHARE_WRITE, NULL,
OPEN_EXISTING, 0, NULL);
if (GetConsoleScreenBufferInfo(hConsole, &Info) == FALSE)
{ {
fprintf(stderr, "GetConsoleScreenBufferInfo: Error: %ld\n", GetLastError()); fprintf(stderr, "GetConsoleScreenBufferInfo: Error: %ld\n", GetLastError());
#ifndef __REACTOS__
/* On ReactOS GetConsoleScreenBufferInfo returns an error if the stdin
handle is redirected to a pipe or file. This stops windres from working. */
return(1); return(1);
#endif
} }
wColor = Info.wAttributes; wColor = Info.wAttributes;
wDefColor = wColor; wDefColor = wColor;

View file

@ -1,4 +1,4 @@
/* $Id: cmd.h,v 1.1 2003/03/20 19:19:22 rcampbell Exp $ /* $Id: cmd.h,v 1.2 2003/06/01 17:06:22 hbirr Exp $
* *
* CMD.H - header file for the modules in CMD.EXE * CMD.H - header file for the modules in CMD.EXE
* *
@ -76,6 +76,7 @@
/* global variables */ /* global variables */
extern HANDLE hOut; extern HANDLE hOut;
extern HANDLE hIn; extern HANDLE hIn;
extern HANDLE hConsole;
extern WORD wColor; extern WORD wColor;
extern WORD wDefColor; extern WORD wDefColor;
extern BOOL bCtrlBreak; extern BOOL bCtrlBreak;

View file

@ -1,4 +1,4 @@
/* $Id: color.c,v 1.1 2003/03/20 19:19:22 rcampbell Exp $ /* $Id: color.c,v 1.2 2003/06/01 17:06:22 hbirr Exp $
* *
* COLOR.C - color internal command. * COLOR.C - color internal command.
* *
@ -70,17 +70,17 @@ VOID SetScreenColor (WORD wColor, BOOL bFill)
if (bFill == TRUE) if (bFill == TRUE)
{ {
GetConsoleScreenBufferInfo (hOut, &csbi); GetConsoleScreenBufferInfo (hConsole, &csbi);
coPos.X = 0; coPos.X = 0;
coPos.Y = 0; coPos.Y = 0;
FillConsoleOutputAttribute (hOut, FillConsoleOutputAttribute (hConsole,
(WORD)(wColor & 0x00FF), (WORD)(wColor & 0x00FF),
(csbi.dwSize.X)*(csbi.dwSize.Y), (csbi.dwSize.X)*(csbi.dwSize.Y),
coPos, coPos,
&dwWritten); &dwWritten);
} }
SetConsoleTextAttribute (hOut, (WORD)(wColor & 0x00FF)); SetConsoleTextAttribute (hConsole, (WORD)(wColor & 0x00FF));
} }

View file

@ -1,4 +1,4 @@
/* $Id: console.c,v 1.1 2003/03/20 19:19:22 rcampbell Exp $ /* $Id: console.c,v 1.2 2003/06/01 17:06:22 hbirr Exp $
* *
* CONSOLE.C - console input/output functions. * CONSOLE.C - console input/output functions.
* *
@ -249,7 +249,7 @@ VOID GetCursorXY (PSHORT x, PSHORT y)
{ {
CONSOLE_SCREEN_BUFFER_INFO csbi; CONSOLE_SCREEN_BUFFER_INFO csbi;
GetConsoleScreenBufferInfo (GetStdHandle (STD_OUTPUT_HANDLE), &csbi); GetConsoleScreenBufferInfo (hConsole, &csbi);
*x = csbi.dwCursorPosition.X; *x = csbi.dwCursorPosition.X;
*y = csbi.dwCursorPosition.Y; *y = csbi.dwCursorPosition.Y;
@ -260,7 +260,7 @@ SHORT GetCursorX (VOID)
{ {
CONSOLE_SCREEN_BUFFER_INFO csbi; CONSOLE_SCREEN_BUFFER_INFO csbi;
GetConsoleScreenBufferInfo (GetStdHandle (STD_OUTPUT_HANDLE), &csbi); GetConsoleScreenBufferInfo (hConsole, &csbi);
return csbi.dwCursorPosition.X; return csbi.dwCursorPosition.X;
} }
@ -270,7 +270,7 @@ SHORT GetCursorY (VOID)
{ {
CONSOLE_SCREEN_BUFFER_INFO csbi; CONSOLE_SCREEN_BUFFER_INFO csbi;
GetConsoleScreenBufferInfo (GetStdHandle (STD_OUTPUT_HANDLE), &csbi); GetConsoleScreenBufferInfo (hConsole, &csbi);
return csbi.dwCursorPosition.Y; return csbi.dwCursorPosition.Y;
} }
@ -280,7 +280,7 @@ VOID GetScreenSize (PSHORT maxx, PSHORT maxy)
{ {
CONSOLE_SCREEN_BUFFER_INFO csbi; CONSOLE_SCREEN_BUFFER_INFO csbi;
GetConsoleScreenBufferInfo (GetStdHandle (STD_OUTPUT_HANDLE), &csbi); GetConsoleScreenBufferInfo (hConsole, &csbi);
if (maxx) if (maxx)
*maxx = csbi.dwSize.X; *maxx = csbi.dwSize.X;