+ //
+ // note however that using MB_ERR_INVALID_CHARS with CP_UTF7 results in
+ // an error (tested under Windows Server 2003) and apparently it is
+ // done on purpose, i.e. the function accepts any input in this case
+ // and although I'd prefer to return error on ill-formed output, our
+ // own wxMBConvUTF7 doesn't detect errors (e.g. lone "+" which is
+ // explicitly ill-formed according to RFC 2152) neither so we don't
+ // even have any fallback here...
+ //
+ // Moreover, MB_ERR_INVALID_CHARS is only supported on Win 2K SP4 or
+ // Win XP or newer and if it is specified on older versions, conversion
+ // from CP_UTF8 (which can have flags only 0 or MB_ERR_INVALID_CHARS)
+ // fails. So we can only use the flag on newer Windows versions.
+ // Additionally, the flag is not supported by UTF7, symbol and CJK
+ // encodings. See here:
+ // http://blogs.msdn.com/michkap/archive/2005/04/19/409566.aspx
+ // http://msdn.microsoft.com/library/en-us/intl/unicode_17si.asp
+ int flags = 0;
+ if ( m_CodePage != CP_UTF7 && m_CodePage != CP_SYMBOL &&
+ m_CodePage < 50000 &&
+ IsAtLeastWin2kSP4() )
+ {
+ flags = MB_ERR_INVALID_CHARS;
+ }
+ else if ( m_CodePage == CP_UTF8 )
+ {
+ // Avoid round-trip in the special case of UTF-8 by using our
+ // own UTF-8 conversion code:
+ return wxMBConvUTF8().MB2WC(buf, psz, n);
+ }
+