[HELP]Error defining swConSize in clear screen function (Console)

A few days ago, my clearing screen function, that I never really edited during that time, started giving an error for no reason.

I searched on Google, and nobody has been having any trouble with it. I searched the function again in several websites (including this own's website version of it), they were all almost the same anyways. I deleted my function and just copy-pasted the original "cls" function from the internet, a few times, still the same error.

So I tested the EXACT SAME function in another program (something like test.cpp) and it worked without any problem, so it's my program's fault. But I tried finding the reason of this happening and it seems everything's in order.





The function is the following:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
void ClearScreen(){

    HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
    COORD coordScreen = { 0, 0 };    // home for the cursor
    DWORD cCharsWritten;
    CONSOLE_SCREEN_BUFFER_INFO csbi;
    DWORD dwConSize;


   // Get the number of character cells in the current buffer.


	if( !GetConsoleScreenBufferInfo( hConsole, &csbi ))
	{
		return;
	}

	dwConSize = csbi.dwSize.X * csbi.dwSize.Y;  //THIS LINE GIVING AN ERROR

   // Fill the entire screen with blanks.

	if( !FillConsoleOutputCharacter( hConsole,        // Handle to console screen buffer
                                     (TCHAR) ' ',     // Character to write to the buffer
                                     dwConSize,       // Number of cells to write
                                     coordScreen,     // Coordinates of first cell
                                     &cCharsWritten ))// Receive number of characters written
	{
		return;
	}

   // Get the current text attribute.

	if( !GetConsoleScreenBufferInfo( hConsole, &csbi ))
	{
		return;
	}

   // Set the buffer's attributes accordingly.

	if( !FillConsoleOutputAttribute( hConsole,         // Handle to console screen buffer
                                     csbi.wAttributes, // Character attributes to use
                                     dwConSize,        // Number of cells to set attribute
                                     coordScreen,      // Coordinates of first cell
                                     &cCharsWritten )) // Receive number of characters written
	{
		return;
	}

   // Put the cursor at its home coordinates.

	SetConsoleCursorPosition( hConsole, coordScreen );

}




I get two errors in the value definition of dwConSize:

dwConSize = csbi.dwSize.X * csbi.dwSize.Y;

error: expected unqualified-id before numeric constant
error: expected ; before numeric constant





I put the function prootype (void ClearScreen();) in a file called Functions.h in my program, and the whole function in a file called Functions.cpp. I'm using the lastest version of the CodeBlocks IDE and compiler.


Edit: I've been playing a little with it, and it seems the problem is the X or Y COORD values, as trying to declare any COORD variable in my code and trying to use coordName.X or coordName.Y gives me the exact same errors.
Last edited on
Are you using any global variables that might be getting in the way? Have you redirected std_output anywhere? This one is pretty tricky but the problem doesn't seem to be in this function.
Makes sense. That's what I soon realized.

But I don't think I've been messing around with anything related to windows functions or std functions, can I get defined examples of what I could have done to cause it to fail like this? What is std_output related to this case?)



In a part of my code I had the letters set to numbers (A=1, B=2...) using #define . Defining X and Y was overriding the values and causing errors. Thanks for the help! I really appreciate it! I would have never thought that would be the source of the problem, I'll now change it.
Last edited on
You. I like you. Please stick around to contribute to our dying WinAPI board. Most people can't find something like that on their own and dragging it out of them is a long and painful process. But you defiantly have at least an insight into the code you are posting, and that is a valuable thing.
Oh, thank you. Was it really THAT admirable?

I need to try and start learning WinAPI and grahics, as I want to get out of the console window. I, however, can't find a good way to learn, it just seems too confusing. I'm getting out for today, can I get a good begginers tutorial for it on youtube or the cplusplus website? It would help :)
Last edited on
The traits that were suggested are very admirable. As far as graphics go both SFML and SDL have super seceded gtk so don't worry about that stuff. I've been a Sys Admin for more then a decade and less then a fifth of the apps I've written use any GUI beyond "MessageBox()". I just have to say that we can get a bit snappy with each other, its a bit like sibling rivalry, so step up to any one who challenges you especially if its me and you'll do fine.
You didn't answer my question :(
Topic archived. No new replies allowed.