Jump to content
  • Advertisement
Sign in to follow this  

[C++] CHAR_INFO.Char.AsciiChar

This topic is 4284 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

In an attempt to create some graphical functionality in the console I'm reading Ben Ryves' tutorial. I'm having some trouble with the code. For example, at one point in the tutorial the following program is given:
#include <stdlib.h>
#include <Windows.h>
#include <stdio.h>

HANDLE wHnd;    // Handle to write to the console.
HANDLE rHnd;    // Handle to read from the console.

int main(int argc, char* argv[]) {

    // Set up the handles for reading/writing:
    wHnd = GetStdHandle(STD_OUTPUT_HANDLE);
    rHnd = GetStdHandle(STD_INPUT_HANDLE);

    // Change the window title:
    SetConsoleTitle("Win32 Console Control Demo");

    // Set up the required window size:
    SMALL_RECT windowSize = {0, 0, 79, 49};
    // Change the console window size:
    SetConsoleWindowInfo(wHnd, TRUE, &windowSize);

    // Create a COORD to hold the buffer size:
    COORD bufferSize = {80, 50};

    // Change the internal buffer size:
    SetConsoleScreenBufferSize(wHnd, bufferSize);

    // Set up the character:
    CHAR_INFO letterA;
    letterA.Char.AsciiChar = 'A';
    letterA.Attributes = 

    // Set up the positions:
    COORD charBufSize = {1,1};
    COORD characterPos = {0,0};
    SMALL_RECT writeArea = {0,0,0,0}; 

    // Write the character:
    WriteConsoleOutput(wHnd, &letterA, charBufSize, characterPos, &writeArea);

    // Move down a line so that we don't overwrite the character:

    // Display a prompt for the user to press a key.

    // Exit
    return 0;
I'm having two problems with that code: SetConsoleTitle("Win32 Console Control Demo"); That line gives me the following error: error C2664: 'SetConsoleTitleW' : cannot convert parameter 1 from 'const char [27]' to 'LPCWSTR' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast Actually, I fixed this one by replacing the line with SetConsoleTitle(TEXT("Win32 Console Control Demo")) I know it works, but really, this isn't how it's supposed to work, right? The second troublemaker is letterA.Char.AsciiChar = 'A' When I run the program I get an '?' instead of an 'A'. I tried some other characters, but the results are the same. I could use the UnicodeChar member instead of AsciiChar, which does work for most of the characters, but then I can't use the extended part of the ASCII-chart. So what's up with CHAR_INFO? Am I doing something wrong here? I'm using VS C++ 8.0, in the case that might have something to do with the problem.

Share this post

Link to post
Share on other sites
Actually, that is how it's supposed to work. The tutorial was written before VS 8.0 and so it assumes that by default you have UNICODE undefined. VS 8.0 changed this and by default defines UNICODE. You can either switch to using Unicode (you can use the extended ASCII characters if you use their UTF16 representations) or you can go into your project properties and switch your build character set to either No Character Set or Multibyte Character Set (I forget which).

Share this post

Link to post
Share on other sites
I've chosen the second option, basically because AsciiChar is simpler and has no drawbacks for me. Setting "Character Set" to "Not Set" did the trick.

Thank you.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!