Jump to content
  • Advertisement
Sign in to follow this  
icqqq

Some problems about the book - Game programming all in one

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

Recently, I have read a book: Game programming all in one. In chapter 7, when I have already finished coding the Monster program, I found that the outputed text is not in English. What can I do to solve this problem? The code is here:
void ConLib::OutputString (char * String)
{
 DWORD Written;

 WriteConsole (m_Screen, String, strlen (String), &Written, NULL);
}
Another problem is the SetTitle() function. When I debug the program, my complier, Visual C++, output the message: Error 1 error C2664: 'SetConsoleTitleW' : cannot convert parameter 1 from 'char *' to 'LPCWSTR' How can I solve it too? The code is here:
void ConLib::SetTitle (char * Title)
{
 SetConsoleTitle (Title);
}
PS: the edition of my book is one [Edited by - icqqq on July 7, 2006 3:11:39 AM]

Share this post


Link to post
Share on other sites
Advertisement
Sounds like UNICODE related issues to me.

Try including <tchar.h> and replacing all the char with TCHAR, and putting all the string constants in _T(), like this


#include <tchar.h>

void f(const TCHAR *c)
{
SetConsoleTitle(c);
}

void g()
{
f(_T("hello"));
}




HTH Paul

Share this post


Link to post
Share on other sites
Thanks!I have already solved the problem of SetTitle().
But the first problem I still can't solve it.
Here is the error message:
error C2664: 'strlen' : cannot convert parameter 1 from 'const TCHAR *' to 'const char *'

Share this post


Link to post
Share on other sites
Visual Studio 2K5 uses unicode by default, unlike earlier versions.
To disable this, enter the properties of your project, open Configuration Properties, General, and set Character Set to Not Set.

Share this post


Link to post
Share on other sites
Actually, I've just been doing a bit of research on this and APPARENTLY (according to MSDN), if you include <tchar.h> and then use _tcslen(), it will map to the correct *len function depending on whether UNICODE is enabled or not, so your code is then properly portable, regardless of the compiler settings.

BTW, there is apparently no such function as wstrlen. I meant wcslen, but that will only work for UNICODE, not normal characters.

If you do decide to adopt the universal approach with <tchar.h>, you also need to declare all your char as TCHAR and wrap any string literals in _T().

NON-PORTABLE:
const char *s="hello";
size_t sz=strlen(s); // will fail with UNICODE on

PORTABLE:
#include <tchar.h>

const TCHAR *s=_T("hello");
size_t sz=_tcslen(s); // will work whether UNICODE is on or not

Please note that I have not actually tested any of this as never yet been forced to care about all this myself. I believe it is now a pretty prevalent issue and one we shall all be forced to account for until single-byte characters are deceased.

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!