Solved

UTF-8 Encoding  Need to convert CHAR to WCHAR?

Posted on 2009-03-31
3
779 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
Comment Utility
>>>> 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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

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…
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.

743 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

11 Experts available now in Live!

Get 1:1 Help Now