This topic is 4333 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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 on other sites
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 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 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 on other sites
Quote:
 Original post by crellbarFirstly, 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 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 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 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 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 on other sites
And if you could be so good as to share that way?

1. 1
Rutin
25
2. 2
3. 3
4. 4
JoeJ
18
5. 5

• 14
• 14
• 11
• 11
• 9
• ### Forum Statistics

• Total Topics
631757
• Total Posts
3002131
×