\documentclass[]{article}
\usepackage{amsmath,graphicx,supertabular,hyperref,tabularx,ifthen}
\title{TIP \#150: Implement the Tk send Command for Windows}
\date{July 25, 2003}
\author{Pat Thoyts}
\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 \#150}&\textbf{Implement the Tk send Command for Windows}\\\hline
Author&

Pat Thoyts \tipmail{patthoyts}{users.sourceforge.net}
\\
Created&Friday, \(\text{25}^{\text{th}}\) July 2003\\
Type&Project\\
Tcl Version&\(8.5\)\\
State&Deferred\\
Vote&Done\\
Version&\tipversion$Revision: 1.6 $\\
Keywords&tk, send\\
Post History&\\
\hline\end{tabularx}\end{center}
\thispagestyle{empty}\pagestyle{empty}
\begin{tipabstract}

This TIP proposes to provide an implementation of the send mechanism for Tk under Windows.
\end{tipabstract}
\tableofcontents\setcounter{page}{0}\clearpage\pagestyle{plain}

\section{Rationale}

The Tk send command is used to provide an X server based mechanism for transmitting information between Tk applications. This provides the basis for remote introspection (tkinspect) and remote control (tkcon). This subsystem has never been implemented under Windows although there are means to emulate this using Tcl's dde package or the comm library. By providing a win32 implementation we help to standardise the Tk command set across platforms and will make it simpler to use this feature from Perl/Tk and Python Tkinter.

\section{Reference Implementation}

This implementation is based upon an integrated version of the winsend package currently at \url{http://tclsoap.sf.net/winsend/.} This uses the Windows Running Object Table to maintain interpreter registration information. This is a global system COM object that is provided as part of the Windows COM automation framework. Its purpose is to provide a single registry for maintaining references to active COM components.

When \textit{tk appname} is called a COM component is created which contains a reference to the Tcl interpreter. This is then registered with the Running Object Table with the registration name containing the Tk app-name. To find available interpreters we use the \textit{winfo interps} command. This iterates over all the registered objects looking for Tk registered names and can then return a list of registered interpreters.

The Tk \textit{send} command is then provided as a COM method call. To perform a send, the client interpreter (or indeed any automation capable COM client) obtains the interpreter reference from the running object table and calls the \textit{Send} method on this object, passing in the command as a string. For the synchronous version this is sufficient. The result is returned using the standard COM method calling and error information can be returned the same way.

Support for the asynchronous send is currently underway but will be modelled closely on the X-based asynchronous send.

There are some advantages in using COM over DDE for the transport mechanism. DDEML has a tendency to use broadcast window messages. If there are any toplevel windows that are not processing their message queues, then DDE gets hung. While a fix has been applied to the Tcl dde package, there remain problems. In contrast the COM-based system never broadcasts. We initiate a conversation with the Running Object Table first and then with the specific application requested. If this application fails to process its message queue then we will get stuck --- but no other poorly behaved application can affect our communication.

A second advantage is than non-Tcl automation capable clients can also call our method. This means that Windows Scripting code (vbscript or jscript) can make use of the send command.

Finally, given a suitable DCOM environment it should also be possible to implement the -displayof feature via Distributed COM. However, I don't see much call for this --- network sockets are a lot simpler to use than DCOM.

\section{Copyright}

This document is placed in the public domain.

\section{Colophon}

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