Solved

UTF-8 Encoding  Need to convert CHAR to WCHAR?

Posted on 2009-03-31
3
788 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays 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.

734 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