Public Group

# Redifine all string literals type in my program

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

## Recommended Posts

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*?

Edited by MarcusAseth

##### Share on other sites

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.

##### Share on other sites

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 )

Edited by MarcusAseth

##### Share on other sites
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 )

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.

##### Share on other sites

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);

1. 1
2. 2
Rutin
19
3. 3
4. 4
khawk
15
5. 5
A4L
13

• 13
• 26
• 10
• 11
• 44
• ### Forum Statistics

• Total Topics
633743
• Total Posts
3013644
×