Using and understanding Unicode

I am currently learning WinAPI programming through online tutorials, so I'm a noob.

According to MSDN, Microsoft recommends that all new programs be Unicode.

I am running Visual Studio 2005 SP1 and all of you know that the 2005 compiler defaults to Unicode. The code below compiles when I change to Multi-Byte character set, but won't compile under Unicode due to the conversion compiler error. But how then do you write an Unicode program?

As I understand it there is actaully two functions for each function that uses strings. A for ANSI and W for Unicode. If I understand correctly the compiler will select the appropriate function depending on how you compile the code. So if my understanding is correct, how come the compiler doesn't use the W function when Unicode is selected in the project's properties? Do I need to include or define something? Or perhaps change something in my code?

So in short my question is how do I write native Unicode programs?

Here is the code that compiles correctly under the Multi-Byte setting:

#include <windows.h>

int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nShowCmd)
{
MessageBox(NULL,
"The Message",
"The Title",
MB_OK | MB_ICONINFORMATION);

return 0;
}
[1587 byte] By [links] at [2007-11-20 8:26:52]
# 1 Re: Using and understanding Unicode
I agree that it would have been nice if the compiler fixed this automatically but for some reason it doesn't.

You have to add the macro _T() to all your statically defined strings. This macro either makes the string being converted to unicode or just don't do anything depending on project settings.

Edit: Just a thought. A null-terminated string is just a special use of a character array. It's hard for the compiler to decide if the array should be interpretad as plain text or not. Maybe that's why there is no auto conversion.
S_M_A at 2007-11-10 22:30:56 >
# 2 Re: Using and understanding Unicode
Not 100% sure but I think you need to include "Tchar.h" for the _T() macro
miteshpandey at 2007-11-10 22:31:55 >
# 3 Re: Using and understanding Unicode
Yes that's right. If you use the wizards to create your project tchar.h is included in stdafx.h
S_M_A at 2007-11-10 22:32:54 >