C++ Solution wont compile - confused

Posted on 2009-04-17
Last Modified: 2013-12-14
Hi there,

I am learning C++ a the minute and trying to compile a simple project I have copied from some literature. The code is translated exactly from the text, however it will not compile. The error is very clear - but i do not have the expertise to fix it. The code falls out at the graphics initialisation function, void init_graphics(); which is part of a header file.

I have attached the function in question along with the error displayed. I am running MS Vista OS and I am compiling with MS Visual Studio 2008 Pro.

Error reads :

error C2664: 'CreateFileW' : cannot convert parameter 1 from 'const char [8]' to 'LPCWSTR'      

Please keep any suggestions light in the lingo. I still have a pointer hangover from yesterday...


void init_graphics();

void init_graphics()


   COORD console_size = {80, 25};

   //open i/o channel to console screen

   hConsole = CreateFile("CONOUT$",GENERIC_WRITE | GENERIC_READ,

                   FILE_SHARE_READ | FILE_SHARE_WRITE,


   //set to 80x25 screen size

   SetConsoleScreenBufferSize(hConsole, console_size);

   //set text to white on black

   SetConsoleTextAttribute( hConsole, (WORD)((0 << 4) | 15) );

   fill_char = '\xDB';  //default fill is solid block



Open in new window

Question by:simondopickup
    LVL 30

    Expert Comment


    this is because your project compiles using UNICODE.

    Write _T( "CONOUT$" ) instead of "CONOUT$" or build the project without UNICODE.

    Hopt that helps,

    LVL 86

    Accepted Solution

    Your solution is probably set to compile as UNICODE, which is the default for new projects, whereas the code you are trying to compile is ANSI-based. Now, instead of rewriting everything to fit into the UNICODE requirements, it is easier to sett your solution to compile as ANSI - open your project properties via "Project|Properties" (or ALT+F7), go to "Configuration Properties|General" and change "Character Set" to "Use Multi-Byte Character Set". That should fix it.

    Author Closing Comment

    Excellent job. I wish i had got on here 3 hours ago.
    Many thanks

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Training Course: Java/J2EE and SOA

    This course will cover both core and advanced Java concepts like Database connectivity, Threads, Exception Handling, Collections, JSP, Servlets, XMLHandling, and more. You'll also learn various Java frameworks like Hibernate and Spring.

    Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
    How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from ( Go to that link and select download selenium in the right hand columnThat will then direct you to their downlo…
    The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
    The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now