Page 1 of 1

Console and encoding

Posted: Sat May 24, 2008 8:55 pm
by AlicVB
Hi,

I have a problem with a small console app I wrote.
I detect a bug (in my app) when I pass args with characters like é,è,...
After a lot of test, I can reproduce the problem with a very small code :

Code: Select all

int main(int argc, char **argv)
{
    wxInitialize();
 
 
    wxCmdLineParser pp(argc,argv);
 
    pp.AddParam(_("File to open"),wxCMD_LINE_VAL_STRING,wxCMD_LINE_PARAM_OPTIONAL);
 
    pp.SetSwitchChars (wxT("-"));
    if (pp.Parse()!=0) return false;
 
    if (pp.GetParamCount()!=0)
    {
        wxPuts(pp.GetParams(0));
        if (wxFileExists(pp.GetParam(0))) wxPuts("OK");
        return false;
    }
}
If the file passed as argument contains accents, The output show the path with a double strange characters in place of my é,è,... Of course, I never see the "OK" (wxwidgets don't find the file).

I think it's an encoding pb, but I can't find any solutions...
If someone can help me...

Thanks in advance !

AlicVB

Posted: Sun May 25, 2008 7:37 pm
by Grrr
Try calling wxLocale::Init() before creating the wxCmdLineParser.

Posted: Mon May 26, 2008 6:49 pm
by AlicVB
I'm afraid this is not the pb : I try wxLocale::Init() with parameters, without, ...

I can add that this code :

Code: Select all

int main(int argc, char **argv)
{
    wxInitialize();
    if (wxFileExists(_T("/home/myhome/été/truc.txt"))) wxPuts(_T("OK"));
    return 1;
}
Doesn't show the 'OK' (and the file pointed exists !)
Any thought ?

Thanks
AlicVB

Posted: Tue May 27, 2008 7:06 am
by Grrr
What platform are you using (Windows, Mac, Linux). Do you use the Unicode build of wxWidgets? Do you use the Unicode build of your application?

Posted: Tue May 27, 2008 9:49 am
by BrokenBrain
Under windows try to put absolute path like this:

"C:\\myfolder\\myfile.txt"

Posted: Tue May 27, 2008 11:31 am
by AlicVB
First, thanks for your answers.
Then, I'm under Linux (Xubuntu 8.04) and I develop with Code::Blocks nightly build.
I have an Unicode version of wxWidgets libs (the ubuntu official one).
But I don't know what how to specify that I want an unicode build of my application.

Thanks
AlicVB

PS : I'll try to edit my signature and specify my OS.

Posted: Tue May 27, 2008 1:38 pm
by BrokenBrain
First of all, i think it depends on your buil of wxwidgets.
When you compiled it you must had specified this option.

Anyway in compiler option you have to define
wxUSE_UNICODE