Click here to Skip to main content
11,932,402 members (54,147 online)
Rate this:
Please Sign up or sign in to vote.
See more: C++ MFC

I have wrote a VC++ project . in design mode for interface of program , I write Persian in caption field and I run the project , But in run mode the Texts is shown " ?????? "

How can I fix it?
Posted 9-Apr-13 12:38pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Ever heard of Unicode and how it works?
Please see:[^],[^].

Unicode is not encoding. One thing you need to know is that on Windows memory representation of Unicode text is UTF-16LE. Please see:[^].

About Unicode and C++:[^],[^].

Unicode with MFC:[^].

Espen Harlinn 9-Apr-13 20:07pm
5'ed! L"Unicode text using escape codes"
Thank you, Espen.
Frankly, at this moment of time its hard for me to understand what escape codes did you mean, but I'm very glad to hear from you.
Espen Harlinn 10-Apr-13 4:14am
OP may have trouble entering the Persian text in his editor and may have to use escape sequences to get the text he wants.

The escape \xhhh consists of the backslash followed by x followed by one or more hexadecimal digits that are taken to specify the value of the desired character. There is no limit to the number of digits in a hexadecimal sequence. A sequence of octal or hexadecimal digits is terminated by the first character that is not an octal digit or a hexadecimal digit, respectively
Oh yes, but it's not advisable to enter hard-coded text in the code, even if this is a part of UI. There are resources for that purpose...
Espen Harlinn 10-Apr-13 9:48am
Perhaps we should mention that he needs to use a font that supports the required characters too?
Oh yes, this too, thank you for the note.
I would note that nearly all modern platforms support Perso-Arabic script (character repertoire) by default; any with wide font support of Unicode will support it.
Espen Harlinn 10-Apr-13 10:00am
That's useful, thanks :)
Sergey Alexandrovich Kryukov 10-Apr-13 10:27am
Rate this: bad
Please Sign up or sign in to vote.

Solution 2


Add this two simple functions and use its.

void MakeUnicodeString(CStringW &cstrW, const char* multibyte)
int nbytes = MultiByteToWideChar(CP_ACP,0,multibyte,-1,0,0);
WCHAR *wstr = new WCHAR[nbytes+2];
cstrW = wstr;
delete [] wstr;

void MakeAnsiString(CString &cstr, const WCHAR* wide)
int nbytes = WideCharToMultiByte(CP_ACP,0,wide,-1,0,0,0,0);
char *str = new char[nbytes+2];
cstr = str;
delete [] str;

Write me for any questions in google++ or blog:[^]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web04 | 2.8.151126.1 | Last Updated 10 Apr 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100