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
Question to unicode arguments of application
Re: Question to unicode arguments of application
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.Starting the *.exe via cmd.exe out of a proper encoded UTF-8 batchfile
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!
Re: Question to unicode arguments of application
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.