TIP 106: Add Encoding Abilities to the [dde] Command

Author:         Harald Oehlmann <[email protected]>
State:          Final
Type:           Project
Vote:           Done
Created:        13-Aug-2002
Tcl-Version:    8.6
Tcl-Branch:     tip-106-impl


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 dde command should be done by a parameter.


Extend the dde commands taking a data argument by the switch -binary:

dde execute ?-async? ?-binary? service topic data

dde poke ?-binary? service topic item data

The argument data is taken as a binary string if the -binary switch is given. Otherwise, it is interpreted as utf-8.


 dde execute -binary CS CS [encoding convertto [encoding system] Äpfel]\0
 dde poke -binary CS CS I [encoding convertto [encoding system] Äpfel]\0


The communication with DDE with external programs uses the format clipboard CF_TEXT and the sent text should be coded in the system encoding (cp1252 in my locale).

Most people who use DDE to communicate with, for example, Excel use the fact that what Excel expects (cp1252) and what Tcl actually sends (utf-8) is identical for 7-bit values and they don't use 8-bit values. Unfortunately, characters used in languages like German, French, etc., are located over this limit and thus are not transferable.

Peter Hardie addressed this point on 2000-10-26 in the Tcl Feature Request at SourceForge (#219185: "dde only handles UTF-8 data (-binary patch available)" http://sf.net/tracker/?func=detail&aid=219185&group_id=10894&atid=360894 ). His proposal was to add a -binary option.

This is a reasonable solution, because any encoding including the system encoding may be used as shown in the upper example.

Reference Implementation

See the tip-106-impl branch in Tcl's fossil repository https://core.tcl-lang.org/tcl/timeline?r=tip-106-impl .

Rejected Alternatives

I proposed to use a switch ?-encoding encoding? which would avoid the preparation of an encoded string by encoding convertto. DDE is so little used at those days so a minimal support is sufficient.

The dde request subcommand already has a parameter -binary. It is more logical to extend this to the other commands.


This document has been placed in the public domain