Solved

when i use this function in c++ the text have arbic it destroied??

Posted on 2010-08-19
13
456 Views
Last Modified: 2012-05-10
hello

i used this function  to convert the variable from  char*  to TCHAR

but the arabic language in the text it appear with charcter that can't be understand it

TCHAR* urlcnw=A2T(urlcn);

can  any body help me to convert between char*   to TCHAR*

without destroy the arabic langauge???

thank you    
0
Comment
Question by:sa3q
[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
  • 7
  • 3
  • 3
13 Comments
 
LVL 33

Expert Comment

by:pgnatyuk
ID: 33474619
Use A2W

A2T depends on the project settings: if there is Unicode character set selected, this A2T will convert the text to the wide characters.
0
 
LVL 40

Expert Comment

by:evilrix
ID: 33475212
What character encoding is used for the narrow representation of Arabic? The original encoding will determine how you convert from narrow to wide. There are a number of encodings it could be, from ANSI (with a specific code page) to UTF8 - which is just another version of Unicode (UTFx are just different Unicode Transformation Formats).
0
 
LVL 33

Expert Comment

by:pgnatyuk
ID: 33475742
I attached a code for your test. Variable p is supposed to contain the converted text.
Windows likes only Unicode (or their version of Unicode). Better to keep all translations/localization in Unicode and do not play with these A2W, mbstowcs, MultiByteToWideChar,...
 

#include <wchar.h>
#include <malloc.h>
#include <locale.h>
#include <stdlib.h>
#include <stdio.h>

int main()
{
    _wsetlocale(LC_ALL,  L"arabic");
    const char* text = "Arabic text";
    wchar_t* p = (wchar_t*)malloc(200);
    p[0] = 0;
    mbstowcs(p, text, 200);
    _wsetlocale(LC_ALL,  L"");
    free(p);
    return 0;
}

Open in new window

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:sa3q
ID: 33475822
evilrix:


the encode that come from  internet page  have  windows-1256   encoding



pgnatyuk:

i used  in  the properties  of the  project  unicode



0
 
LVL 33

Expert Comment

by:pgnatyuk
ID: 33476040
The code I posted is a Unicode project too.
Anyway A2T is not a solution. You can try to use your A2T with #pragma setlocale("arabic"), but I don't think it will be an acceptable solution for you.

0
 
LVL 40

Expert Comment

by:evilrix
ID: 33476768
>> the encode that come from  internet page  have  windows-1256   encoding
Ok, that seems to imply the narrow encoding is ANSI not UTF8 so I would follow what pgnatyuk is suggesting.
0
 
LVL 40

Expert Comment

by:evilrix
ID: 33476892
NB. Just to note (as this is overlooked by a lot of Windows programmers thanks to Microsoft's confusing [and mostly inaccurate] terminology)...

Just because something is wide does not mean it is Unicode. Just because something is narrow don't mean it is not Unicode!

UTF8 and UTF16 are both Unicode transformation formats and both represent Unicode, the former is narrow and the latter is wide.

hen Microsoft speak of Unicode they are referring to UTF16 and when they speak of non-Unicode they are (usually) referring to ANSI. If you want to convert from narrow to wide you MUST know what the encoding of the narrow form is otherwise your conversion will not behave as you expect. This was the reason for my original question.

This is slightly off topic but I get very vexed at how Microsoft confuse people with their redefinition of terminology! :)
0
 
LVL 33

Expert Comment

by:pgnatyuk
ID: 33477616
>>This is slightly off topic but I get very vexed at how Microsoft confuse people with their redefinition of terminology! :)

This multibyte character set from Microsoft is totally useless. They can rename it in simplified English. :)


0
 
LVL 1

Author Comment

by:sa3q
ID: 33479164
evilrix: & pgnatyuk:

i used  setlocal


but  it still not ok  you can  see the image to  see the problem  in arabic text
thank  you
asas.png
0
 
LVL 33

Accepted Solution

by:
pgnatyuk earned 500 total points
ID: 33479256
Why you don't use the code I posted?
If you already took one line, why you cannot apply wcstombs?
How I see it should be something like

_wsetlocale(LC_ALL,  L"arabic");
TCHAR* urlcnw = (wchar_t*)malloc(1024);
urlcnw[0] = 0;
mbstowcs(urlscnw, urlcn, 1000);

Do not forget to delete this urlcnw when you will not need it. It is correct for your code with A2T too.
0
 
LVL 33

Expert Comment

by:pgnatyuk
ID: 33479307
I hope your Windows supports Arabic?
At least this system font used in the VS debugger can show the Arabic text.
0
 
LVL 1

Author Closing Comment

by:sa3q
ID: 33481572
thanks
0
 
LVL 33

Expert Comment

by:pgnatyuk
ID: 33482091
You are welcome
0

Featured Post

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

710 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