\documentclass[]{article}
\usepackage{amsmath,graphicx,supertabular,hyperref,tabularx,ifthen}
\title{TIP \#106: Add Encoding Abilities to the [dde] Command}
\date{August 13, 2002}
\author{Harald Oehlmann}
\urlstyle{sf}
\setlength{\parskip}{1ex}
\setlength{\parindent}{0pt}
\def\tipversion$#1${\texttt{\$#1\$}}
\def\tiplangle#1{\ensuremath{<}}
\def\tiprangle#1{\ensuremath{>}}
\def\tipbar#1{\ensuremath{|}}
\def\tipmail#1#2{\(\langle\){\small\expandafter\url{#1@#2}}\(\rangle\)}
\ifx\pdfoutput\undefined
\newcommand{\tipimage}[2]{\typeout{Make sure you download #1.eps}\ifthenelse{\lengthtest{0.8\textwidth>#2}\and\lengthtest{0pt<#2}}{\includegraphics{#1.eps}}{\includegraphics[width=0.8\textwidth]{#1.eps}}}
\newcommand{\tipxref}[1]{}
\newcommand{\tipxrefend}{}
\else
\newcommand{\tipimage}[2]{\typeout{Make sure you create #1.pdf}\ifthenelse{\lengthtest{0.8\textwidth>#2}\and\lengthtest{0pt<#2}}{\includegraphics{#1.pdf}}{\includegraphics[width=0.8\textwidth]{#1.pdf}}}
\pdfcatalog{/PageMode /UseOutlines}
\newcommand{\tipxref}[1]{\pdfannotlink attr {/C [0.5 0.5 1.0] /Border [0 0 1]} goto name {#1}}
\newcommand{\tipxrefend}{\pdfendlink}
\fi
\newenvironment{tipabstract}{\begin{abstract}}{\end{abstract}}
\begin{document}\maketitle
\begin{center}\begin{tabularx}{\linewidth}{|r@{: }X|}\hline
\textbf{TIP \#106}&\textbf{Add Encoding Abilities to the [dde] Command}\\\hline
Author&

Harald Oehlmann \tipmail{harald.oehlmann}{elmicron.de}
\\
Created&Tuesday, \(\text{13}^{\text{th}}\) August 2002\\
Type&Project\\
Tcl Version&\(8.6\)\\
State&Final\\
Vote&Done\\
Version&\tipversion$Revision: 1.14 $\\
Post History&\\
\hline\end{tabularx}\end{center}
\thispagestyle{empty}\pagestyle{empty}
\begin{tipabstract}

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 \textbf{dde} command should be done by a parameter.
\end{tipabstract}
\tableofcontents\setcounter{page}{0}\clearpage\pagestyle{plain}

\section{Specification}

Extend the \textbf{dde} commands taking a data argument by the switch \textbf{-binary}:

\begin{quote}
\textbf{dde execute} ?\textbf{-async}? ?\textbf{-binary}? \textit{service topic data}
\end{quote}

\begin{quote}
\textbf{dde poke} ?\textbf{-binary}? \textit{service topic item data}
\end{quote}

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

Examples:
\begingroup\small\begin{verbatim}
 dde execute -binary CS CS [encoding convertto [encoding system] Äpfel]\0
 dde poke -binary CS CS I [encoding convertto [encoding system] Äpfel]\0
\end{verbatim}
\endgroup

\section{Rationale}

The communication with DDE with external programs uses the format clipboard \textit{CF\_TEXT} and the sent text should be coded in the system encoding (\textit{cp1252} in my locale).

Most people who use DDE to communicate with, for example, Excel use the fact that what Excel expects (\textit{cp1252}) and what Tcl actually sends (\textit{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)'' [\url{http://sf.net/tracker/?func=detail&aid=219185&group_id=10894&atid=360894}]). His proposal was to add a \textbf{-binary} option.

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

\section{Reference Implementation}

See the \textit{tip-106-impl} branch in Tcl's fossil repository [\url{https://core.tcl.tk/tcl/timeline?r=tip-106-impl}].

\section{Rejected Alternatives}

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

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

\section{Copyright}

This document has been placed in the public domain

\section{Colophon}

\textit{TIP AutoGenerator --- written by Donal K. Fellows}
\end{document}
