Jump to content
  • Advertisement
Sign in to follow this  
Frank_Li

Older Code in VS 2005

This topic is 4352 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

I'm working out of an older book and I'm trying to output a games score on the screen. Some of the old code in this book does not work in VS 2005. I'm new to C++ and windows programing (I like Java so much more) so I'm unsure on how to fix it. I've tried type casting and some older deprecated functions I found in some tutorials (probably too old also) but no luck.
int score = 24;
TCHAR szText[64];
RECT rect = {275,0,325,50};
wsprintf(szText,"%d",score);
DrawText(hDC,szText,-1,&rect,DT_SINGLELINE);

The error I get is: Error 1 error C2664: 'wsprintfW' : cannot convert parameter 2 from 'const char [3]' to 'LPCWSTR' I know it has something to do with unicode but I'm unclear about what's really going on and why it doesn't work. What the hell is LPCWSTR?

Share this post


Link to post
Share on other sites
Advertisement
Go to your project settings, under general, change character set to use multibyte character set.

Share this post


Link to post
Share on other sites
Oh, great that was easy! I've already spent an hour looking for a solution!
What did that change do? Now I the project is compatible with ASCII and UNICODE?
Why wasn't this an issue in VS 6.0?

Share this post


Link to post
Share on other sites
Most Windows API functions and structures come in two versions: a narrow character version and a wide character version. These are also known as ANSI and Unicode versions. For example, CreateWindow() is actually two functions: CreateWindowA() and CreateWindowW(). A macro transformation maps CreateWindow() calls to one of these two functions depending on what preprocessor definitions are in effect. If UNICODE is defined, CreateWindow() is actually CreateWindowW(). If it isn't defined CreateWindow() is actually CreateWindowA(). In MSVC, the Character Set project property controls whether or not UNICODE is defined. In MSVC 2005, unlike previous versions, this property defaults to Unicode for new projects.

The difference between the two versions is that the ANSI versions use CHARs for their character type in strings. The wide character versions use WCHARs for their character types. Normal string literals in C++ are narrow characters, which is what the CHAR type works out to. However, WCHAR eventually turns into wchar_t, not char, and pointers to normal char strings are not compatible with pointers to wchar_ts. In order to create a wchar_t string literal you would prefix the string with L. For example "this is a narrow character string" vs. L"this is a wide character string".

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!