Solved

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

Posted on 2010-08-19
13
450 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
>> 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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 40

Expert Comment

by:evilrix
Comment Utility
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
Comment Utility
>>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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
thanks
0
 
LVL 33

Expert Comment

by:pgnatyuk
Comment Utility
You are welcome
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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 user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

772 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

12 Experts available now in Live!

Get 1:1 Help Now