[wx3.0.2][wxMSW] Displaying unicode chars Topic is 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.
Post Reply
Rudra
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 224
Joined: Fri Sep 13, 2013 2:59 pm

[wx3.0.2][wxMSW] Displaying unicode chars

Post by Rudra »

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
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

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

Post by PB »

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
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 224
Joined: Fri Sep 13, 2013 2:59 pm

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

Post by Rudra »

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
Can't get richer than this
Can't get richer than this
Posts: 867
Joined: Sun May 13, 2012 11:42 pm
Location: France
Contact:

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

Post by eranon »

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
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 224
Joined: Fri Sep 13, 2013 2:59 pm

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

Post by Rudra »

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: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

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

Post by doublemax »

(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
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 224
Joined: Fri Sep 13, 2013 2:59 pm

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

Post by Rudra »

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: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

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

Post by doublemax »

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
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 224
Joined: Fri Sep 13, 2013 2:59 pm

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

Post by Rudra »

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.
Post Reply