Solved

UTF-8 Encoding  Need to convert CHAR to WCHAR?

Posted on 2009-03-31
3
783 Views
Last Modified: 2012-05-06
Hi all,

I want to work My application in Non-english Os.

As of now , my application follow ISO-8859-1 encoding.For I18N, i m going to change UTF-8.

My dought is , part of my application is c/c++.

Shall i need to convert char (char* and LPSTR)  to wchar (wchar * and LPWSTR) or No need to convert  my appl ?

(why i m asking is,  i wrote small stand alone program to read a non english (Japanese) letter from registry Using LPSTR/CHAR.Its Working)

Any help will be appreciated?
 
0
Comment
Question by:vak73
3 Comments
 
LVL 39

Accepted Solution

by:
itsmeandnobodyelse earned 50 total points
ID: 24031126
>>>> i m going to change UTF-8.

UTF-8 is a 8bit multibyte format for UNICODE which wasn't well supported by C++. Nevertheless you could store the text and strings in normal char arrays (not wchar_t) but it is badly readable if actually you have non-ASCII letters to print.

When using wchar_t (with MS VC compiler) you have 16bit chars with a character set that MS calls UNICODE. Then, indeed you have to turn from char to wchar_t and LPCSTR to LPWCSTR and so on and each literal you have to prefix with a L, e. g. L"Hello World". Or, you use the so-called T-switch with TCHAR and LPCTSTR, ... and literals as _T("Hello World). For the latter you would need to set your project to UNICODE. I personally do not recommend to using the T-switch cause it doesn't allow a proper use of both ANSI strings and wide strings and generates a lot of problems you wouldn't have without T-switch.


0
 
LVL 17

Assisted Solution

by:CSecurity
CSecurity earned 50 total points
ID: 24038032
when you want to change your all chars to w_char, you should:
check your all string functions like strcpy, strcat, strstr and etc and then change them to wcscpy, wcscat, wcsstr and etc.

then check your API functions:
in default, when you use for example CreateFile() API function, you call CreateFileA() that suitable for english filenames but you should change all of API function calls that has A/W to W
I mean if you use CreateFile change this to CreateFileW
or you can add #define UNICODE top of #include <windows.h> like this:
#define UNICODE
#include <windows.h>
or if you are using VS, you can go Project -> Settings -> C/C++ tab
in the C/C++ tab, you'll see preprocessor definitions like this:
WIN32,_DEBUG,_WINDOWS,_MBCS
you can change _MBCS to _UNICODE. then it should be:
WIN32,_DEBUG,_WINDOWS,_UNICODE
then, all of your API calls will be W as default (I mean as non-english strings)

regards
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.

816 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now