convert a prorams from ASCII to UNICODE

  • Thread starter Thread starter Frank
  • Start date Start date
F

Frank

I have a c program that uses the "A" version of API files.

Since it runs on XP I'd guess it would be better if it used the "W"
versions.


Why is it using the "A" version. I looked in properties and can't find where
it is instructed to use the "A"

What do I have to do to get it to use the "W" versions and more importantly,
what must I change in my program.

For example, all char definitions become what??



Thanks in advance
 
You must define UNICODE (or _UNICODE) and recompile your program (and, of course,
use generic types like TCHAR (or _TCHAR) instead of char or wchar_t . Also you always
must use strings with _T or _TEXT macros: use _T("string") instead of "string").
Take a look to tchar.h, winnt.h and winuser.h to get an idea how all of this works.

http://msdn2.microsoft.com/en-us/library/06b9yaeb(VS.80).aspx


Regards
 
The doc you sited below is very helpful.

Leaves me with one question. It says:
Do not use the str family of functions with Unicode strings, which are
likely to contain embedded null bytes.

What is the family of functions I'm suppose to use?



Thanks for all the help
 
Leaves me with one question. It says:
Do not use the str family of functions with Unicode strings, which are likely to
contain embedded null bytes.

What is the family of functions I'm suppose to use?

Unicode strings can contain null characters inside(*) so you must not use the str
familiy functions (strcpy, strlen, etc). You must use the tcs family functions
(tcscpy, tsclen, etc). You can avoid this double thinking :-p if you use the _tsc
family macros for ascii/unicode compatibility (_tcscpy, _tcslen, etc).

* because each character occupies 2 bytes and some character mapping only needs 1
byte (the remaining one is 0, NULL). The end terminator in unicode strings is a
double NULL.

Another useful article:
http://www.codeproject.com/cpp/unicode.asp


Regards

--
Cholo Lennon
Bs.As.
ARG
 
Why is it using the "A" version. I looked in properties and can't find
where it is instructed to use the "A"
This is whay you end up with "A" versions, although you don't explicitely use
them: http://www.mihai-nita.net/20050306b.shtml

What do I have to do to get it to use the "W" versions and more
importantly, what must I change in my program.

For example, all char definitions become what??

Add Unicode configurations to your project
(for instance ReleaseU derived from Release and and DebugU derived from
Debug). In order to build Unicode versions you need to define *both*
UNICODE and _UNICODE, and to change the entry point.
You have to exeplicitely do this in older VS6 and older, but you have
one single option in newer versions:
http://www.mihai-nita.net/20060723a.shtml

Then start changing all the data types to generic data types:
char to TCHAR, wrap strings in _T("...") (or TEXT("..."), or _TEXT("..."),
is the same thing). Change all C api to generic strcpy to _tcscpy, etc.
(in the MSDN doc each C function has a section called "Generic-Text Routine
Mappings", use the stuff in the "TCHAR.H routine" column).

Helpful links:
- Then take a look at this, for the high-level steps:
http://www.microsoft.com/globaldev/getwr/steps/wrg_unicode.mspx
- Then see "Converting a project to Unicode: Part 1-9" (Jochen's post),
where Michael Kaplan takes an ANSI project and migrates it to Unicode,
explaining what he's doing and why.
- Then Cholo's link is good to fill in the gaps and API details.
 
Another good site


Thanks again

Cholo Lennon said:
Unicode strings can contain null characters inside(*) so you must not use
the str familiy functions (strcpy, strlen, etc). You must use the tcs
family functions (tcscpy, tsclen, etc). You can avoid this double thinking
:-p if you use the _tsc family macros for ascii/unicode compatibility
(_tcscpy, _tcslen, etc).

* because each character occupies 2 bytes and some character mapping only
needs 1 byte (the remaining one is 0, NULL). The end terminator in unicode
strings is a double NULL.

Another useful article:
http://www.codeproject.com/cpp/unicode.asp


Regards
 
Thanks a lot

Mihai N. said:
This is whay you end up with "A" versions, although you don't explicitely
use
them: http://www.mihai-nita.net/20050306b.shtml



Add Unicode configurations to your project
(for instance ReleaseU derived from Release and and DebugU derived from
Debug). In order to build Unicode versions you need to define *both*
UNICODE and _UNICODE, and to change the entry point.
You have to exeplicitely do this in older VS6 and older, but you have
one single option in newer versions:
http://www.mihai-nita.net/20060723a.shtml

Then start changing all the data types to generic data types:
char to TCHAR, wrap strings in _T("...") (or TEXT("..."), or _TEXT("..."),
is the same thing). Change all C api to generic strcpy to _tcscpy, etc.
(in the MSDN doc each C function has a section called "Generic-Text
Routine
Mappings", use the stuff in the "TCHAR.H routine" column).

Helpful links:
- Then take a look at this, for the high-level steps:
http://www.microsoft.com/globaldev/getwr/steps/wrg_unicode.mspx
- Then see "Converting a project to Unicode: Part 1-9" (Jochen's post),
where Michael Kaplan takes an ANSI project and migrates it to Unicode,
explaining what he's doing and why.
- Then Cholo's link is good to fill in the gaps and API details.
 
Back
Top