how to handle the unicode

I saw a book it doesn't use the unicode, but I use VS 2010, it default uses the unicode.

my book segment(no unicode):
1
2
3
4
5
6
7
8
9
char msgText[256];

SendMessage(hComboBox, CB_GETLBTEXT, (WPARAM)index, (LPARAM)msgText);

MessageBox(0, msgText, "Combo Message", MB_OK);

if(strlen(msgText) > 0) {
    SendMessage(hDlg, CB_ADDSTRING, 0, LPARAM(msgText));
}


What should I do, I can do with strlen, MessageBox...?
thanks help
If you want to keep old ANSI behaviour, just delete _UNICODE and UNICODE macros from prepocesor definitions, altough new applications should use only Unicode these days.

The recommended way is to include <tchar.h> and use TEXT() macro for string literals and TCHAR instead of char, this way your application will work in both Ansi and Unicode mode without changes to source code.
I don't know about VS 2010, as I have VS 2008. But in VS 2008 you can go into the project properties and set what modoran above suggested using the list box they provide. In mine the choices are multibyte, wide char, and not set. Using the GUI like that just changes the macros I imagine - like modoran suggests. In the end though, you need to fully understand this character set issue and learn the TCHAR macros. In the short run though, so as to help you use the ansi book, I'd just change the char set in use.
You can also convert your code to make it unicode.
1
2
3
4
5
6
7
8
9
10
wchar_t msgText[256]; // wchar_t -> Unicode char

SendMessage(hComboBox, CB_GETLBTEXT, (WPARAM)index, (LPARAM)msgText);

MessageBox(0, msgText, L"Combo Message", MB_OK);
// L"Text" -> Unicode literal text

if(wcslen(msgText) > 0) { // wcslen -> Unicode strlen
    SendMessage(hDlg, CB_ADDSTRING, 0, LPARAM(msgText));
}
Topic archived. No new replies allowed.