[wx-dev] RFC: UTF-8 build mode for wx: wxUSE_UNCODE

Vadim Zeitlin vadim at wxwindows.org
Mon Mar 5 03:08:42 PST 2007


On Tue, 20 Feb 2007 11:34:29 +0100 Lukasz Michalski <lm at zork.pl> wrote:

LM> 2. Windows Service, main():
LM> 
LM>   TCHAR exe_path[STRPATHBUFFERLENGTH - 50];
LM>   ::GetModuleFileName(0, exe_path, sizeof(exe_path));
LM> #if wxUSE_UNICODE
LM>   swprintf(strPath, wxT("%s"), exe_path);
LM> #else
LM>   sprintf(strPath, "%s", exe_path);
LM> #endif

 Here you use wxUSE_UNICODE as synonym for _UNICODE. I'm tempted to say
that such usage shouldn't be very common as I hope people would rather
replace the last 5 lines with a single strPath.Printf(_T("%s"), exe_path)
statement.

LM> #if wxUSE_UNICODE
LM>   wxArrayString args;
LM>   const wxChar *cmdLine = ::GetCommandLine();

 This won't compile as wxChar will be a class. In fact just about anything
using "wxChar *" won't compile any more.

LM>   if (cmdLine)
LM>     args = wxCmdLineParser::ConvertStringToArgs(cmdLine);
LM>   //argc = args.GetCount();
LM>   // +1 here for the terminating NULL
LM>   wxChar **wargv = new wxChar *[argc + 1];
LM>   for ( int i = 0; i < argc; i++ )
LM>     wargv[i] = wxStrdup(args[i]);
LM> 
LM>   wxCmdLineParser pParser(argc, wargv);

 FWIW, wxCmdLineParser also accepts cmdLine directly, no need to do this.

LM> 4. Conviersion from libxml2 xmlChar to wxString:
LM> 
LM> #if wxUSE_UNICODE 
LM>   return wxString((const char*)(const xmlChar*)pNode.getName(),wxConvUTF8);
LM> #else
LM>   return dba::wxTools::UTF8ToLocal((const char*)(const xmlChar*)pNode.getName());
LM> #endif

 This should continue to work if wxUSE_UNICODE becomes always 1.

 Regards,
VZ





More information about the wx-dev mailing list