Question to unicode arguments of application

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
Herb
Earned a small fee
Earned a small fee
Posts: 15
Joined: Wed Dec 07, 2016 12:26 pm

Question to unicode arguments of application

Post by Herb »

Hello,

I have built an unicode-Gui-application
- on Windows 10
- with wxwidgets 3.1.5
- built with IDE CodeBlocks
- using GCC compiler 10.2 from winlibs https://winlibs.com/#download-release

The application is started with one argument being the name of a directory.
As long as this argument does only contain ASCII characters everything is working fine.

But in case of using unicode characters (e.g. a German umlaut or a chinese character) I see the following strange behaviour for the following code:

OnInitCmdLine:
- sets only the CommandLineDescription
OnCmdLineParsed:
- checkes the amount of used arguments
- in case of only 1 argument it does (for testing purposes)
wxMessageBox(parser.GetParam(0));
wxString hlp = wxString::FromUTF8(parser.GetParam(0));
wxMessageBox(hlp);

Now I have the following behaviour
(1)
Starting the *.exe inside CodeBlocks - handing the argument via Project --> Set Programs Arguments
the first MessageBox shows the correct byte-sequence for all characters: Ascii and unicode
the second Messagebox shows the proper string as expected.

(2)
Starting the *.exe via cmd.exe out of a proper encoded UTF-8 batchfile
the first MessageBox shows a wrong byte-sequence for unicode characters
the second Messagebox shows an empty string, which means wxString::FromUTF8 could not convert the argument.

Can someone explain where these differences come from?
What am I missing or what am I doing wrong?

Thanks for your help in advance
Best regards
herb
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Question to unicode arguments of application

Post by doublemax »

Starting the *.exe via cmd.exe out of a proper encoded UTF-8 batchfile
I don't think Windows handles UTF-8 batch files by default. Google tells me you need to use "chcp 65001" to change the code page inside the batch file to make it work.

AFAIK Windows Unicode applications always get their parameters UCS-2 encoded, and as wxCmdLineParser::GetParam() returns a wxString, you should never have to deal with the encoding anyway.
Use the source, Luke!
Manolo
Can't get richer than this
Can't get richer than this
Posts: 827
Joined: Mon Apr 30, 2012 11:07 pm

Re: Question to unicode arguments of application

Post by Manolo »

CodeBlocks has an option to set the active encoding. I don't know if it affects only the code editor or the whole of strings used any where.
Post Reply