Solved

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

Posted on 2010-08-19
13
452 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
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…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

943 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now