WriteConsoleOutputCharacter not working

May 25, 2010 at 12:59pm
Hello everyone,
here is my simple function:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
void frame() {
	char ul = (char)201;
	char ur = (char)187;
	char dl = (char)200;
	char dr = (char)188;
	char v = (char)186;
	char h = (char)205;
	char cr = (char)204;
	char cl = (char)185;
	char cu = (char)202;
	char cd = (char)203;
	COORD dab;
	dab.X = 0;
	dab.Y = 0;
	WriteConsoleOutputCharacter(hnd, &ul, 1, dab, &chrswrt);
	dab.X = csbi.srWindow.Right;
	for(dab.X = 1; dab.X < csbi.srWindow.Right; dab.X++)
		WriteConsoleOutputCharacter(hnd, &h, 1, dab, &chrswrt);
	WriteConsoleOutputCharacter(hnd, &ur, 1, dab, &chrswrt);
	dab.Y = csbi.srWindow.Bottom;
	WriteConsoleOutputCharacter(hnd, &dr, 1, dab, &chrswrt);
	dab.X = 0;
	WriteConsoleOutputCharacter(hnd, &dl, 1, dab, &chrswrt);
}

but somehow some characters just don't appear. The last function call and the one in the loop. Chars themselves appears if i put them, for example, at first, but the other ones fails to appear. What is the case?
May 25, 2010 at 1:38pm
What chars are they? There are some caracter which are invisible (control characters) and some aren't in the font for the console.
May 25, 2010 at 1:56pm
They are all line drawing characters -- all MS console fonts have them.

It works properly for me. Are you sure that

1) You properly initialized:
1
2
hnd = GetStdHandle( STD_OUTPUT_HANDLE );
GetConsoleScreenBufferInfo( hnd, &csbi );

2) Your console window isn't scrolled

BTW, your global variable names are terrible. Likewise, chrswrt doesn't need to be a global.

Hope this helps.
May 25, 2010 at 2:37pm
Yes, i initialized everything fine. So that's mean it has something to do with my computer... Btw what character set you had when tested this?

I made it global because i didn't wanted to make it again many times in different functions.

For me both with character set Not Set and Multibyte something it only outputs three corner characters, even the down right one doesn't show up.
Last edited on May 25, 2010 at 2:42pm
May 25, 2010 at 7:57pm
If you right-click on the console window's icon and select "Properties", then click the "Font" tab, it should read either "Raster Fonts" or "Lucida Console". (If you see the corners, then the font isn't the problem.)

The other thing to check is to make sure the window is not scrolled any, and that the character attribute for the line is not the same color for foreground and background where you are writing it...

May 25, 2010 at 9:21pm
Thanks for reply. Ok now something new - when i changed to Lucida Console font i saw ? in places of my missing symbols. But the strange thing is that the very same symbols are printed normally in some other places of the screen (not all though).

Ok now something really strange - i changed my first printed symbol to dl (instead of ul), and then all the other symbols were printed correctly. That totally makes no sense...

EDIT: i somehow strangely solved the problem by changing the first printed symbol few times and re-executing code, and finally it showed up correctly. But again it makes no sense how is it working...
Last edited on May 25, 2010 at 9:26pm
May 26, 2010 at 2:34am
It sounds to me like you are goofing-up with the pointers somewhere...
Topic archived. No new replies allowed.