Solved

UTF-8 Encoding  Need to convert CHAR to WCHAR?

Posted on 2009-03-31
3
789 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
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.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

635 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