+ conv = &wxConvLibc;
+ }
+ else if ( format == wxIPC_UTF8TEXT )
+ {
+ conv = &wxConvUTF8;
+ }
+ else // no conversion necessary for wxIPC_UNICODETEXT
+ {
+ realData = (LPBYTE)data;
+ realSize = size;
+ }
+
+ if ( conv )
+ {
+ const char * const text = (const char *)data;
+ const size_t len = size/sizeof(char);
+
+ realSize = conv->ToWChar(NULL, 0, text, len);
+ if ( realSize == wxCONV_FAILED )
+ return false;
+
+ realData = (LPBYTE)buffer.GetWriteBuf(realSize*sizeof(wchar_t));
+ if ( !realData )
+ return false;
+
+ realSize = conv->ToWChar((wchar_t *)realData, realSize, text, len);
+ if ( realSize == wxCONV_FAILED )
+ return false;
+ }
+#else // !wxUSE_UNICODE
+ if ( format == wxIPC_UNICODETEXT )
+ {
+ conv = &wxConvLibc;
+ }
+ else if ( format == wxIPC_UTF8TEXT )
+ {
+ // we could implement this in theory but it's not obvious how to pass
+ // the format information and, basically, why bother -- just use
+ // Unicode build
+ wxFAIL_MSG( wxT("UTF-8 text not supported in ANSI build") );
+
+ return false;
+ }
+ else // don't convert wxIPC_TEXT
+ {
+ realData = (LPBYTE)data;
+ realSize = size;
+ }
+
+ if ( conv )
+ {
+ const wchar_t * const wtext = (const wchar_t *)data;
+ const size_t len = size/sizeof(wchar_t);
+
+ realSize = conv->FromWChar(NULL, 0, wtext, len);
+ if ( realSize == wxCONV_FAILED )
+ return false;
+
+ realData = (LPBYTE)buffer.GetWriteBuf(realSize*sizeof(char));
+ if ( !realData )
+ return false;
+
+ realSize = conv->FromWChar((char*)realData, realSize, wtext, len);
+ if ( realSize == wxCONV_FAILED )
+ return false;