-
writing to the console
Hello everybody.
I'm trying to write to the console with WriteConsoleOutput, but I get some
errors during compilation.
The code I've written so far:
Code:
//--------------------------------------------------------------------------------------------------
//Display a 80cols x 25 rows fixed size console
//--------------------------------------------------------------------------------------------------
void DisplayCon(char target[]){
COORD bufferSize = {80, 25};
COORD TopLeft = {0,0};
SMALL_RECT Out_buf;
Out_buf.Left = 0;
Out_buf.Top = 0;
Out_buf.Right = 24;
Out_buf.Bottom = 79;
WriteConsoleOutput(wHnd, target, bufferSize, TopLeft, Out_buf);
return;
}
When I compile I get these errors:
Code:
Type error in argument 2 to 'function'; expected 'const CHAR_INFO *' but found 'char *'.
Type error in argument 5 to 'function'; expected 'PSMALL_RECT' but found 'SMALL_RECT'.
regarding the WriteConsoleOutput call.
What am I missing?
The array I'm using to store the data to be displayed: target[] should
be a CHAR_INFO structure. If I want to use the same area using union,
the same that I'm using for array target[], how should I define the structure?
CHAR_INFO has already a union inside:
Code:
typedef struct _CHAR_INFO { // chi
union { /* Unicode or ANSI character */
WCHAR UnicodeChar;
CHAR AsciiChar;
} Char;
WORD Attributes; // text and background colors
} CHAR_INFO, *PCHAR_INFO;
I am not able to figure how should I declare the structure with a union to
have the same area of 8000 bytes usable in both array mode and struct mode.
Thanks for any help you can give me.
-
Start with
Code:
CHAR_INFO array[10]; // pick your size
Then do
Code:
array[0].Char.AsciiChar = mystring[0]; // and the rest of them
array[0].Attributes = 0; // RTM for RED, FLASH, whatever...
Finally,
Code:
WriteConsoleOutput(wHnd, array, bufferSize, TopLeft, &Out_buf);
-
Thanks salem. This is a different solution, but it can be feasible.
I have the
Code:
AsciiChar
Attributes
In an array of characters source[4000] in this shape:
Code:
first character:
source[0] contains the AsciiChar
source[1] contains the Attributes
second character:
source[2] contains the AsciiChar
source[3] contains the Attributes
and so on.
If I assign the values:
Code:
array[0].Char.AsciiChar = source[0];
array[0].Attributes =source[1];
and so on
I leave the remaining 2 bytes of the structure uninitialized, but I want that they
contain both a space [ASCII 32].
So I need to put some value also in the remaining 2 bytes of the
structure. How do I access them?