Solved

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

Posted on 2010-08-19
13
455 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
  • 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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

Suggested Solutions

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
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 be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

821 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