Jump to content
  • Advertisement
Sign in to follow this  
crellbar

Help, I'm going mad!!

This topic is 4333 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 I've been working on my custom assert for the past few hours and it isn't working. Well it is, however when compiling for windows in debug mode (#undef NDEBUG, #define WIN32) it spits the dumbest error at me (in VS.NET 2005). It appears to try to replace the TEXT(stream_...) call in Assert.h with the letter L thus leaving Lstream_.... I then get an error saying Lstream_ does not exits etc. If any one has time could you try to compile it and tell me what you get. If you have any idea why it is doing this I would also be extremely grateful (but not in a gay way... sorry been watchin Peter Kay). http://crellbar.com/crap/BastardCode.zip Cheers in advance to anyone who can help.

Share this post


Link to post
Share on other sites
Advertisement
You're running up against a Microsoft 'feature' that makes it easier to use different string encodings. Unfortunately it uses the a macro called TEXT() to do this. This will be defined in one of the MS header files somewhere, and might have instructions for how you can disable the behaviour in your program, typically with a #define of your own. Obviously you can use a differently named call to TEXT instead, which will work around the problem.

Share this post


Link to post
Share on other sites
Firstly, Thanks for the quick reply.

Sorry - I must have left that bit out - I'm trying to use the microsoft TEXT() macro - I'm playing with a assert in a windows MessageBox and for the content it only accepts LpOmgMs (or something) which TEXT() will convert my char* to.

TEXT() just seems to be spazzing out on me. My old assert setup is very similar and works, but this one (even when I copy the code directly from my old one) just keeps screaming 'L' at me as an error message.

Share this post


Link to post
Share on other sites

if(MessageBox(NULL,TEXT((stream_.str().c_str())), TEXT("Assertion Failed."), 0))

the macro is used for string literals, like the caption parameter that you passed there. it merely prepends L to the macro parameter. i'm not sure what the best idea here would be since i never use win32 or unicode. i'd probably use ifdefs and hackish stuff, so somebody else should answer this. [grin]

Share this post


Link to post
Share on other sites
Quote:
Original post by crellbar
Firstly, Thanks for the quick reply.

Sorry - I must have left that bit out - I'm trying to use the microsoft TEXT() macro - I'm playing with a assert in a windows MessageBox and for the content it only accepts LpOmgMs (or something) which TEXT() will convert my char* to.

TEXT() just seems to be spazzing out on me. My old assert setup is very similar and works, but this one (even when I copy the code directly from my old one) just keeps screaming 'L' at me as an error message.


TEXT() doesn't convert a char * variable to a wide char string - it can only work with string litterals - that's why it puts a L in front of your string.

To convert a char* to a wchar_t*, you have to use mbstowcs().

Regards,

Share this post


Link to post
Share on other sites
The TEXT macro is only for string literals ("something"), not actual objects. The reason it's complaining about L is that wide string literals indeed look like this:
L"something"
And all TEXT does is to add L. Your actual problem is that you are using std::stringstream, the actual type you should use depend on the character set you are using, if you use standard characters (char), then std::stringstream is ok. If you need wide characters (wchar_t), then you should use std::wstringstream. Since your envirornment supports TEXT (it isn't standard), then it most likely also have a TCHAR to represent the current character type. Therefore if you have a TCHAR type then you could just use std::basic_stringstream<TCHAR> (you could use a typedef to shorten the name).

Share this post


Link to post
Share on other sites
Cheers everyone, I understand the TEXT() macro now.

Still cant get the bugger to work though. I'll keep looking around.

Share this post


Link to post
Share on other sites
Use TEXT() or _T() only on string literals, never on variables.

Try starting with the compiler libraries' supplied assert macro (which works), and start modifying it from there.

Share this post


Link to post
Share on other sites
Thanks fot the help everyone.
I'm sorted now - the mcbtocws (or whatever it was) gave me a few issues for some reason but there was another way which fixed it all nicely.

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!