UNICODE char type

Ok,

I am an eMbeddedVB programmer. I am currently migrating to eVC++. I am not a C++ Guru however, and I am running into some problems pertaining to the use of UNICODE char variables. Is there a source that will aid me in the understanding of using UNICODE char variables. I realize that when programming in UNICODE that the variables used should be counted as one byte and not two. However, string operations do not appear to work the same as what I am used to.

For example:

char* szLanguage = "eMbedded Visual C++"

AND

wchar_t* szLanguage = "eMbedded Viusal C++"

do not work the same and I get compile errors.

I am most interested in the use of Character arrays such as
char* szLanguage[10];
where you have an array of strings with 10 characters each. However, what is the Windows CE equivalent. Using a standard multidimensional char/TCHAR/wchar_t array seems to be very complex and hard to manage.

Thanks to anyone.

Ed Rush
[1021 byte] By [Edward Rush] at [2007-11-17 15:39:39]
# 1 Re: UNICODE char type
Why don't you use the CString type:

CString strLanguage = _T("eMbedded Visual C++");

The CString class has millions of string functions built into it already...
alanr at 2007-11-9 12:22:34 >
# 2 Re: UNICODE char type
I am trying to avoid the CString Class. The devices that I manage are small and industrial. I want the apps to be as small as possible and I have read many things about CString objects and how bulky they are. But then again, this is conclusion is from reading and not from experimenting. The processing that I am doing is done on an incoming string of about 100 characters that I have to divide and seperate from delimiters. Then I must validate each element of the string.
My experience is in eMbedded VB and since eMbedded VB is no longer going to be supported, I have great incentive to migrate into Visual C++, C++ and C.

Thanks.

Ed Rush
Edward Rush at 2007-11-9 12:23:34 >
# 3 Re: UNICODE char type
Each of the ansii string functions have corresponding UNICODE functions. For example, strcmp() is wcscmp(). Learn to use the Help (MSDN) that is available with eVC++. When you search for the ansii string function that you are familiar with, MSCN described the UNICODE version too. There are even functions that convert from ansii to UNICODE, but you probably will rarely use them.

TCHAR *string1 = _T("someting")
TCHAR *string2 = _T("another string")

int test = _tcscmp(string1, strin2);

In the above, TCHAR, _T() and _tcscmp() are macros defined in tchar.h that map text to either ansii or UNICODE, depending on compiler settings. When UNICODE is defined, they map to the UNICODE versions, otherwise to the ansii versions. If you use these macros, then your code can be compiled correctly by either eVC++ for WinCE, or by VC++6 on the desktop.
stober at 2007-11-9 12:24:32 >
# 4 Re: UNICODE char type
I should have read your second post more carefully. Since your program is going to be receiving ansii strings you will need to convert them to UNICODE. I have ported a Win32 library to WinCE, and is avilable free at http://www.glnetsoftware.com/
It does not contain any MFC.

Here is an example of how to convert the characters:

char *ansii_string = "some text"
int size = strlen(ansii_string);
// permanent UNICODE storage
TCHAR* unicode_string = new TCHAR[size+1];
// convert from ansii to unicode
mbstowcs(unicode_string, ansii_string, size+1);
stober at 2007-11-9 12:25:37 >
# 5 Re: UNICODE char type
The way I use strings (Is ued to be a VB programmer and went to C when I started coding for CE) is to use TCHARs.

To initialise a string with a value to start with I use
TCHAR szString = TEXT("This is the string contents.");

To create a string variable to recieve text from a control etc, I use
TCHAR szString[50];
GetWindowText ( hwnd , szString , 50 );

To create 10 strings of length 50, use
TCHAR szString[50][10];

I hope this is helpful, I remember having similar problems getting my head round strings in C when I started!

Tone
TonyCoupland at 2007-11-9 12:26:35 >
# 6 Re: UNICODE char type
That will work for the strings you create within your own UNICODE program, but not for the strings received from TCP or serial, unless you know that those strings are also UNICODE. If they are not, then you need to convert them.:)
stober at 2007-11-9 12:27:39 >