Unicode and the outside world

We have seen that it was easy to write Unicode programs using wxWidgets types and macros, but it has been also mentioned that it isn't quite enough. Although everything works fine inside the program, things can get nasty when it tries to communicate with the outside world which, sadly, often expects ANSI strings (a notable exception is the entire Win32 API which accepts either Unicode or ANSI strings and which thus makes it unnecessary to ever perform any conversions in the program). GTK 2.0 only accepts UTF-8 strings.

To get a ANSI string from a wxString, you may use the mb_str() function which always returns an ANSI string (independently of the mode - while the usual c_str() returns a pointer to the internal representation which is either ASCII or Unicode). More rarely used, but still useful, is wc_str() function which always returns the Unicode string.

ymasuda 平成17年11月19日