+ wxCHECK_MSG( format == wxIPC_TEXT ||
+ format == wxIPC_UTF8TEXT ||
+ format == wxIPC_UNICODETEXT,
+ false,
+ wxT("wxDDEServer::Execute() supports only text data") );
+
+ wxMemoryBuffer buffer;
+ LPBYTE realData = NULL;
+ size_t realSize = 0;
+ wxMBConv *conv = NULL;
+
+ // Windows only supports either ANSI or UTF-16 format depending on the
+ // build, so we need to convert the data if it doesn't use it already
+#if wxUSE_UNICODE
+ if ( format == wxIPC_TEXT )
+ {
+ 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;
+
+ 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;
+
+ // We need to pass the size of the buffer to DdeClientTransaction() and
+ // not the length of the string.
+ realSize *= sizeof(wchar_t);
+ }
+#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