<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE TIP SYSTEM "http://www.tcl.tk/cgi-bin/tct/tip/tipxml.dtd">
<!-- Converted at Sat May 25 20:17:14 GMT 2013 -->
<!-- TIP AutoGenerator - written by Donal K. Fellows -->

<TIP number='106'>
<header><title>Add Encoding Abilities to the [dde] Command</title><author address="mailto:harald.oehlmann@elmicron.de">Harald Oehlmann</author><status type='project' state='final' tclversion="8.6" vote='after'>$Revision: 1.14 $</status><history></history><created day='13' month='aug' year='2002' /></header>
<abstract>When using Windows DDE communication with non-Tcl programs, the encoding of the exchanged strings is mostly needed to be the system encoding. Selection of this behaviour should be possible with in the <emph style="bold">dde</emph> command should be done by a parameter.</abstract>
<body><section title="Specification">
<para>Extend the <emph style="bold">dde</emph> commands taking a data argument by the switch <emph style="bold">-binary</emph>:</para>
<quote><emph style="bold">dde execute</emph> ?<emph style="bold">-async</emph>? ?<emph style="bold">-binary</emph>? <emph style="italic">service topic data</emph></quote>
<quote><emph style="bold">dde poke</emph> ?<emph style="bold">-binary</emph>? <emph style="italic">service topic item data</emph></quote>
<para>The argument <emph style="italic">data</emph> is taken as a binary string if the <emph style="bold">-binary</emph> switch is given. Otherwise, it is interpreted as utf-8.</para>
<para>Examples:</para>
<verbatim><vline encoding='base64'>IGRkZSBleGVjdXRlIC1iaW5hcnkgQ1MgQ1MgW2VuY29kaW5nIGNvbnZlcnR0byBbZW5jb2Rpbmcgc3lzdGVtXSDEcGZlbF1cMA==</vline><vline encoding='base64'>IGRkZSBwb2tlIC1iaW5hcnkgQ1MgQ1MgSSBbZW5jb2RpbmcgY29udmVydHRvIFtlbmNvZGluZyBzeXN0ZW1dIMRwZmVsXVww</vline></verbatim>
</section>
<section title="Rationale">
<para>The communication with DDE with external programs uses the format clipboard <emph style="italic">CF_TEXT</emph> and the sent text should be coded in the system encoding (<emph style="italic">cp1252</emph> in my locale).</para>
<para>Most people who use DDE to communicate with, for example, Excel use the fact that what Excel expects (<emph style="italic">cp1252</emph>) and what Tcl actually sends (<emph style="italic">utf-8</emph>) is identical for 7-bit values and they don&apos;t use 8-bit values. Unfortunately, characters used in languages like German, French, etc., are located over this limit and thus are not transferable.</para>
<para>Peter Hardie addressed this point on 2000-10-26 in the Tcl Feature Request at SourceForge (#219185: &quot;dde only handles UTF-8 data (-binary patch available)&quot; [<url ref="http://sf.net/tracker/?func=detail&amp;aid=219185&amp;group_id=10894&amp;atid=360894"/>]). His proposal was to add a <emph style="bold">-binary</emph> option.</para>
<para>This is a reasonable solution, because any encoding including the system encoding may be used as shown in the upper example.</para>
</section>
<section title="Reference Implementation">
<para>See the <emph style="italic">tip-106-impl</emph> branch in Tcl&apos;s fossil repository [<url ref="https://core.tcl.tk/tcl/timeline?r=tip-106-impl"/>].</para>
</section>
<section title="Rejected Alternatives">
<para>I proposed to use a switch ?<emph style="bold">-encoding</emph> <emph style="italic">encoding</emph>? which would avoid the preparation of an encoded string by <emph style="bold">encoding convertto</emph>. DDE is so little used at those days so a minimal support is sufficient.</para>
<para>The <emph style="bold">dde request</emph> subcommand already has a parameter <emph style="italic">-binary</emph>. It is more logical to extend this to the other commands.</para>
</section>
<section title="Copyright">
<para>This document has been placed in the public domain</para>
</section>
</body></TIP>
