• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 347
  • Last Modified:

C++ Solution wont compile - confused

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...

Simon

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,
                   0L, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0L);
   //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
   clear_screen();
   }

Open in new window

0
simondopickup
Asked:
simondopickup
1 Solution
 
ZoppoCommented:
Hi,

this is because your project compiles using UNICODE.

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

Hopt that helps,

ZOPPO
0
 
jkrCommented:
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.
0
 
simondopickupAuthor Commented:
Excellent job. I wish i had got on here 3 hours ago.
Many thanks
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now