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.
[wx3.0.2][wxMSW] Displaying unicode chars Topic is solved
Re: [wx3.0.2][wxMSW] Displaying unicode chars
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.
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.
Re: [wx3.0.2][wxMSW] Displaying unicode chars
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.
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.
- eranon
- 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
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"]
Re: [wx3.0.2][wxMSW] Displaying unicode chars
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.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)?
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.
Re: [wx3.0.2][wxMSW] Displaying unicode chars
(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.
Which is basically exactly what eranon asked.
Use the source, Luke!
Re: [wx3.0.2][wxMSW] Displaying unicode chars
The encoding is UTF-8. I convert it to wxString like,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.
Code: Select all
std::string dataFromServer = DataFromServer();
wxString str(dataFromServer);
R
Re: [wx3.0.2][wxMSW] Displaying unicode chars
Code: Select all
std::string dataFromServer = DataFromServer();
wxString str(dataFromServer);
Use wxString::FromUTF8 like eranon already suggested.
Use the source, Luke!
Re: [wx3.0.2][wxMSW] Displaying unicode chars
Yes, Following works for me,doublemax wrote: Use wxString::FromUTF8 like eranon already suggested.
Code: Select all
wxString uniData(data.c_str(), wxConvUTF8); // std::string data;
or
wxString uniData(data);
uniData = wxString::FromUTF8(uniData);
Thanks,
R.