Jump to content
  • Advertisement
Sign in to follow this  
cdlong

Unicode Help

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

Hi all, I'm currently working on fixing some bugs in an C++ unicode project. This unicode stuff is new to me so I'm trying to find my way as I go. I've managed to get rid of most of the bugs but I'm stuck on this one: A messagebox is popping up (as it should) with a correct title but the message text is all square symbols (there's apparentely some type of conversion issue). My Code for this function: void ShowError (const ErrorStatus es, const TCHAR* szMsg) /* PURPOSE: To show an alert dialog box with a message about the error found, and a message supplied by the user */ { const TCHAR* pszErrorText = (TCHAR*)acadErrorStatusText (es) ; TCHAR szBuffer [256] ; if (NULL == pszErrorText) { // An error getting the error message for es _tcscpy (szBuffer, szMsg) ; } else { _tprintf (szBuffer, _T("%s\n(ARX ERROR:<%s>)"), szMsg, pszErrorText) ; } ::MessageBox (NULL, szBuffer, _T("DWGINFO"),0); } MessageBox is expecting a LPCWSTR for arguements but as you can see szBuffer is a TCHAR, I can't figure out how to change it. Any info would be greatly appreciated. Thanks,

Share this post


Link to post
Share on other sites
Advertisement

/*
PURPOSE: To show an alert dialog box with a message about the
error found, and a message supplied by the user
*/

{
const TCHAR* pszErrorText = (TCHAR*)acadErrorStatusText (es) ;
TCHAR szBuffer [256] ;

if (NULL == pszErrorText) {
// An error getting the error message for es
_tcscpy (szBuffer, szMsg) ;
} else {
// This should be _stprintf, not _tprintf
_tprintf (szBuffer, _T("%s\n(ARX ERROR:<%s>)"), szMsg, pszErrorText) ;
}

::MessageBox (NULL, szBuffer, _T("DWGINFO"),0);
}





I labeled the error in your code. You're using the wrong function. You need to replace _tprintf with _stprintf. What you're doing now is printing szBuffer with useless arguements, and what it seems you're trying to do is print the value of _T(...) into szBuffer.

Share this post


Link to post
Share on other sites
Nytegard,

That worked like a charm, you made it looks so easy, I definitely appreciate the help.

MJP,

Haven't read the whole entry yet but it definitely looks intersting, thanks for the info.

Share this post


Link to post
Share on other sites
Definately read his journal entry.

Infact, I'd suggest replacing a lot of your code with something like:


void ShowError (const ErrorStatus es, const std::tstring szMsg)
/*
PURPOSE: To show an alert dialog box with a message about the
error found, and a message supplied by the user
*/

{
const std::tstring pszErrorText( (TCHAR*)acadErrorStatusText(es) ) ;
std::tstring szBuffer;

if (pszErrorText.empty() )
{
// An error getting the error message for es
szBuffer = szMsg;
}
else
{
std::tstringstream os;
os << szMsg << _T("\n(ARX ERROR:<") << pszErrorText << _T(")");
szBuffer = os.str();
}

::MessageBox (NULL, szBuffer.c_str(), _T("DWGINFO"), 0);
}




You can either have tstring && tstringstream defined as follows:


namespace std
{
typedef basic_string<TCHAR> tstring;
typedef basic_stringstream<TCHAR> tstringstream;
...
}

OR

namespace std
{
#if defined UNICODE || defined _UNICODE

typedef wstring tstring;
typedef wstringstream tstringstream;
...
#else
typedef string tstring;
typedef stringstream tstringstream;
...
#endif
}




Mainly, this will get rid of a lot of errors which could occur with C Strings, such as buffer overruns, etc, and give you all the handy benefits of C++ strings.

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!