[wx3.0.2][wxMSW] Displaying unicode chars  [SOLVED]

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Rudra
I live to help wx-kind
I live to help wx-kind
Posts: 175
Joined: Fri Sep 13, 2013 2:59 pm

[wx3.0.2][wxMSW] Displaying unicode chars

Postby Rudra » Wed Dec 06, 2017 12:00 pm

Hi,

In my wx application on window, the wxStaticText and wxSimpleHtmlListBox are unable to show the unicode chars. Same works fine on OSX. It shows the garbage chars.

I tried updating the project's property "Character Set" from "Use Unicode Character Set" to "Use Multi-Byte Character Set" but I get error as follows,
E:\External\WxWidgets\Include\wx/msw/winundef.h(38):error C2664: 'CreateDialogParamW' : cannot convert parameter 2 from 'LPCTSTR' to 'LPCWSTR'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
E:\External\WxWidgets\Include\wx/msw/winundef.h(38): error C2664: 'CreateFontW' : cannot convert parameter 14 from 'LPCTSTR' to 'LPCWSTR'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
E:\External\WxWidgets\Include\wx/msw/winundef.h(38): error C2664: 'CreateWindowExW'
...

I also tried to rebuilt the wxWidgets libs with "Use Multi-Byte Character Set" setting and use in project but having same errors.

Not sure how to fix this. Please suggest.

Thanks,
R.

PB
wxWorld Domination!
wxWorld Domination!
Posts: 1345
Joined: Sun Jan 03, 2010 5:45 pm

Re: [wx3.0.2][wxMSW] Displaying unicode chars

Postby PB » Wed Dec 06, 2017 1:19 pm

wxWidgets certainly CAN display unicode characters

You provided little information but my guess is you have the strings in the source files and use MSVS. I would recommend against this practice as this can be very brittle when switching between platforms and compilers. If it is a rare unicode char occurrence, you can get around with encoding the character with \u, otherwise use literal strings in English wrapped in _() and translate the string in the message catalogs .

If you like to live dangerously, I believe you need to tell the compiler about source and execution charset, see e.g. https://msdn.microsoft.com/en-us/library/mt708821.aspx, information about BOM in particular. Do not set character set to MBCS in MSVS, make sure you use Unicode.

Rudra
I live to help wx-kind
I live to help wx-kind
Posts: 175
Joined: Fri Sep 13, 2013 2:59 pm

Re: [wx3.0.2][wxMSW] Displaying unicode chars

Postby Rudra » Wed Dec 06, 2017 2:02 pm

Thanks for the reply.

I am getting the string data from server which may contain the unicode chars (e.g •∆π™℅¶♂♀¿¡¥€¢£) as well. The server sends data in json format. I parse it into std::string using a json lib. I create the wxString from parsed std::string then populate the wxStaticText and wxSimpleHtmlListBox but I see garbage value only.

Same is fine on OSX.

Thanks
R.

User avatar
eranon
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 661
Joined: Sun May 13, 2012 11:42 pm
Location: France
Contact:

Re: [wx3.0.2][wxMSW] Displaying unicode chars  [SOLVED]

Postby eranon » Wed Dec 06, 2017 3:59 pm

When you receive the bytes from the server, how do you save/write them in a buffer (eg. char* appended to a wxMemoryBuffer), then how do you interpret/read this buffer afterward (eg. wxString::FromUTF8 from buff.GetData)?
[Ind. dev. - wxWidgets 3.0/3.1 under "Win 7 64-bit, TDM64-GCC" + "OS X 10.9, LLVM Clang"]

Rudra
I live to help wx-kind
I live to help wx-kind
Posts: 175
Joined: Fri Sep 13, 2013 2:59 pm

Re: [wx3.0.2][wxMSW] Displaying unicode chars

Postby Rudra » Thu Dec 07, 2017 6:59 am

eranon wrote:When you receive the bytes from the server, how do you save/write them in a buffer (eg. char* appended to a wxMemoryBuffer), then how do you interpret/read this buffer afterward (eg. wxString::FromUTF8 from buff.GetData)?


Client is connected with server using web-socket. Server sends/accepts data in json format. I use a web-socket lib which gives me data into std::string.
On init, client gets data from server which is stored in std::vector<std::string>. Same is used to populate a list on client. Clicking the list-item requests more data from server. Server returns the response.

I see that only rendering/displaying is the problem. I get the appropriate response from server when I request data on a list-item clicked in spite of it is showing garbage chars.

Thanks,
R.

User avatar
doublemax
Moderator
Moderator
Posts: 11536
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: [wx3.0.2][wxMSW] Displaying unicode chars

Postby doublemax » Thu Dec 07, 2017 7:42 am

(Not all) Unicode characters can be stored in a std::string (which uses 8 bit characters), so there must be some kind of encoding involved, usually UTF-8. First we need to know which encoding the data you receive uses, then we need to know (code?) how you convert that into wxString.

Which is basically exactly what eranon asked.
Use the source, Luke!

Rudra
I live to help wx-kind
I live to help wx-kind
Posts: 175
Joined: Fri Sep 13, 2013 2:59 pm

Re: [wx3.0.2][wxMSW] Displaying unicode chars

Postby Rudra » Thu Dec 07, 2017 8:16 am

doublemax wrote:(Not all) Unicode characters can be stored in a std::string (which uses 8 bit characters), so there must be some kind of encoding involved, usually UTF-8. First we need to know which encoding the data you receive uses, then we need to know (code?) how you convert that into wxString.

Which is basically exactly what eranon asked.


The encoding is UTF-8. I convert it to wxString like,

Code: Select all

std::string dataFromServer =  DataFromServer();
wxString str(dataFromServer);


Thanks,
R

User avatar
doublemax
Moderator
Moderator
Posts: 11536
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: [wx3.0.2][wxMSW] Displaying unicode chars

Postby doublemax » Thu Dec 07, 2017 9:00 am

Code: Select all

std::string dataFromServer =  DataFromServer();
wxString str(dataFromServer);
This assumes encoding in the current locale.

Use wxString::FromUTF8 like eranon already suggested.
Use the source, Luke!

Rudra
I live to help wx-kind
I live to help wx-kind
Posts: 175
Joined: Fri Sep 13, 2013 2:59 pm

Re: [wx3.0.2][wxMSW] Displaying unicode chars

Postby Rudra » Thu Dec 07, 2017 10:20 am

doublemax wrote:Use wxString::FromUTF8 like eranon already suggested.

Yes, Following works for me,

Code: Select all

 wxString uniData(data.c_str(), wxConvUTF8);         // std::string data;
 or
wxString uniData(data);
uniData = wxString::FromUTF8(uniData);


Thanks for help.

Thanks,
R.


Return to “C++ Development”

Who is online

Users browsing this forum: No registered users and 11 guests