Send Unicode data as UTF-8 text when using DDE-based IPC

This is a more hackish but more compatible solution to the problem of
data sent using wxIPC_UTF8TEXT format being simply lost when using DDE
for IPC classes. We must use CF_TEXT for the DDE to pass our data, but
we can try to decode it as UTF-8 in the client and assume it was sent in
this format if it worked. This obviously suffers from false positives as
any ASCII string will still be assumed to be UTF-8, but there shouldn't
be any real harm coming from this.

This change also makes sending data in wxIPC_UTF{16,32}TEXT formats work
as well by converting it to UTF-8.

Update the sample to call Advise() with both wxIPC_UTF{8,16}TEXT formats
and remove the now unnecessary wxDDEConnection::m_dataType member.

Closes #17900.
This commit is contained in:
Vadim Zeitlin
2018-12-27 00:21:49 +01:00
parent 09bf235a59
commit 20cb47c1c4
4 changed files with 88 additions and 9 deletions

View File

@@ -268,8 +268,15 @@ void MyServer::Advise()
{
const wxDateTime now = wxDateTime::Now();
m_connection->Advise(m_connection->m_advise, now.Format());
wxString str = wxString::FromUTF8("\xd0\x9f\xd1\x80\xd0\xb8\xd0\xb2\xd0\xb5\xd1\x82");
m_connection->Advise(m_connection->m_advise, str + " (using UTF-8)");
str += " (using wchar_t)";
m_connection->Advise(m_connection->m_advise,
str.wc_str(), (str.length() + 1)*sizeof(wchar_t),
wxIPC_UNICODETEXT);
// This one uses wxIPC_TEXT by default.
const wxString s = now.FormatTime() + " " + now.FormatDate();
m_connection->Advise(m_connection->m_advise, s.mb_str(), wxNO_LEN);