Advertisement

Redifine all string literals type in my program

Started by July 19, 2017 08:10 PM
4 comments, last by Shaarigan 7 years, 4 months ago

I was wondering redifining all string literals in my program from "const char*" to "const wchar_t*" ? was feasable.


MessageBox(0, "Important stuff", 0, 0);

The code above is how my code looks, since I changed the project character set from Unicode to multybite character set.

If I hadn't, would look like this


	MessageBox(0, TEXT("Important stuff"), 0, 0);
	MessageBox(0, L"Important stuff", 0, 0);

And I don't like random L all over the place or extra typing trough TEXT(), that's why I'm not using Unicode right now, but I know I will need it in order to use kanjis, therefore I would like to be able to type 


MessageBox(0, "漢字禁止", 0, 0);

Without weird L or TEXT macro.

There is a way for me to instruct the compiler or whoever is that handle this stuff that all the literal strings in my program default to const wchar_t* instead of const char*? :S

I wish. No, you will have to prefix everything with L. And don't bother using the TEXT macro at all, as it's pointless. Personally I explicitly call the W versions of Windows API functions - always MessageBoxW, never MessageBox. I am not on board with the macro horrors MS manufactured.

SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.
Advertisement

that's a bummer x_x

I just tried and can't even #define w or W to be L... guess random L it is, then... x_x

Though what's the advantadge of calling MessageBoxW explicitly instead of MessageBox macro ? Is it a personal liking or something can actually go wrong? (In which case I wold like to know beforehand :D)

2 hours ago, MarcusAseth said:

Though what's the advantadge of calling MessageBoxW explicitly instead of MessageBox macro ? Is it a personal liking or something can actually go wrong? (In which case I wold like to know beforehand :D)


MessageBox(0, L"Whatever", 0, 0);

That requires UNICODE defined in the preprocessor to work correctly. Which is irritating. I want my code to build correctly with the minimum amount of configuration. Using the actual function name also has the added perk that Intellisense gives you an actual function declaration to work with.

SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.

I personally prefer the A postfix functions over the macro choosen or unicode ones. I havent had anything that couldnt be used in plain ASCII/ANSI encoding yet


MessageBoxA(0, "Whatever", 0, 0);

 

This topic is closed to new replies.

Advertisement