Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2010-08-19
13
Medium Priority
?
470 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
Technology Partners: 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 2000 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
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 member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

916 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