| [25] | 1 | '\" | 
|---|
 | 2 | '\" Copyright (c) 1997 Sun Microsystems, Inc. | 
|---|
 | 3 | '\" Copyright (c) 2001 ActiveState Corporation. | 
|---|
 | 4 | '\" | 
|---|
 | 5 | '\" See the file "license.terms" for information on usage and redistribution | 
|---|
 | 6 | '\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. | 
|---|
 | 7 | '\"  | 
|---|
 | 8 | '\" RCS: @(#) $Id: dde.n,v 1.24 2008/01/18 15:59:22 dkf Exp $ | 
|---|
 | 9 | '\"  | 
|---|
 | 10 | .so man.macros | 
|---|
 | 11 | .TH dde n 1.3 dde "Tcl Bundled Packages" | 
|---|
 | 12 | .BS | 
|---|
 | 13 | '\" Note:  do not modify the .SH NAME line immediately below! | 
|---|
 | 14 | .SH NAME | 
|---|
 | 15 | dde \- Execute a Dynamic Data Exchange command | 
|---|
 | 16 | .SH SYNOPSIS | 
|---|
 | 17 | .sp | 
|---|
 | 18 | \fBpackage require dde 1.3\fR | 
|---|
 | 19 | .sp | 
|---|
 | 20 | \fBdde servername\fR ?\fB\-force\fR? ?\fB\-handler \fIproc\fR? ?\fB\-\|\-\fR? ?\fItopic\fR? | 
|---|
 | 21 | .sp | 
|---|
 | 22 | \fBdde execute\fR ?\fB\-async\fR? \fIservice topic data\fR | 
|---|
 | 23 | .sp | 
|---|
 | 24 | \fBdde poke\fR \fIservice topic item data\fR | 
|---|
 | 25 | .sp | 
|---|
 | 26 | \fBdde request\fR ?\fB\-binary\fR? \fIservice topic item\fR | 
|---|
 | 27 | .sp | 
|---|
 | 28 | \fBdde services \fIservice topic\fR | 
|---|
 | 29 | .sp | 
|---|
 | 30 | \fBdde eval\fR ?\fB\-async\fR? \fItopic cmd \fR?\fIarg arg ...\fR? | 
|---|
 | 31 | .BE | 
|---|
 | 32 |  | 
|---|
 | 33 | .SH DESCRIPTION | 
|---|
 | 34 | .PP | 
|---|
 | 35 | This command allows an application to send Dynamic Data Exchange (DDE) | 
|---|
 | 36 | command when running under Microsoft Windows. Dynamic Data Exchange is | 
|---|
 | 37 | a mechanism where applications can exchange raw data. Each DDE | 
|---|
 | 38 | transaction needs a \fIservice name\fR and a \fItopic\fR. Both the | 
|---|
 | 39 | \fIservice name\fR and \fItopic\fR are application defined; Tcl uses | 
|---|
 | 40 | the service name \fBTclEval\fR, while the topic name is the name of the | 
|---|
 | 41 | interpreter given by \fBdde servername\fR. Other applications have their | 
|---|
 | 42 | own \fIservice names\fR and \fItopics\fR. For instance, Microsoft Excel | 
|---|
 | 43 | has the service name \fBExcel\fR. | 
|---|
 | 44 | .PP | 
|---|
 | 45 | .SH "DDE COMMANDS" | 
|---|
 | 46 | .PP | 
|---|
 | 47 | The following commands are a subset of the full Dynamic Data Exchange | 
|---|
 | 48 | set of commands. | 
|---|
 | 49 | .TP | 
|---|
 | 50 | \fBdde servername \fR?\fB\-force\fR? ?\fB\-handler \fIproc\fR? ?\fB\-\|\-\fR? ?\fItopic\fR? | 
|---|
 | 51 | . | 
|---|
 | 52 | \fBdde servername\fR registers the interpreter as a DDE server with | 
|---|
 | 53 | the service name \fBTclEval\fR and the topic name specified by \fItopic\fR. | 
|---|
 | 54 | If no \fItopic\fR is given, \fBdde servername\fR returns the name | 
|---|
 | 55 | of the current topic or the empty string if it is not registered as a | 
|---|
 | 56 | service. If the given \fItopic\fR name is already in use, then a | 
|---|
 | 57 | suffix of the form | 
|---|
 | 58 | .QW " #2" | 
|---|
 | 59 | or | 
|---|
 | 60 | .QW " #3" | 
|---|
 | 61 | is appended to the name to make it | 
|---|
 | 62 | unique. The command's result will be the name actually used. The | 
|---|
 | 63 | \fB\-force\fR option is used to force registration of precisely the | 
|---|
 | 64 | given \fItopic\fR name. | 
|---|
 | 65 | .RS | 
|---|
 | 66 | .PP | 
|---|
 | 67 | The \fB\-handler\fR option specifies a Tcl procedure that will be called to | 
|---|
 | 68 | process calls to the dde server. If the package has been loaded into a | 
|---|
 | 69 | safe interpreter then a \fB\-handler\fR procedure must be defined. The | 
|---|
 | 70 | procedure is called with all the arguments provided by the remote | 
|---|
 | 71 | call. | 
|---|
 | 72 | .RE | 
|---|
 | 73 | .TP | 
|---|
 | 74 | \fBdde execute\fR ?\fB\-async\fR? \fIservice topic data\fR | 
|---|
 | 75 | . | 
|---|
 | 76 | \fBdde execute\fR takes the \fIdata\fR and sends it to the server indicated | 
|---|
 | 77 | by \fIservice\fR with the topic indicated by \fItopic\fR. Typically, | 
|---|
 | 78 | \fIservice\fR is the name of an application, and \fItopic\fR is a file to | 
|---|
 | 79 | work on.  The \fIdata\fR field is given to the remote application. | 
|---|
 | 80 | Typically, the application treats the \fIdata\fR field as a script, and the | 
|---|
 | 81 | script is run in the application.  The \fB\-async\fR option requests | 
|---|
 | 82 | asynchronous invocation.  The command returns an error message if the | 
|---|
 | 83 | script did not run, unless the \fB\-async\fR flag was used, in which case | 
|---|
 | 84 | the command returns immediately with no error. | 
|---|
 | 85 | .TP | 
|---|
 | 86 | \fBdde poke \fIservice topic item data\fR | 
|---|
 | 87 | . | 
|---|
 | 88 | \fBdde poke\fR passes the \fIdata\fR to the server indicated by | 
|---|
 | 89 | \fIservice\fR using the \fItopic\fR and \fIitem\fR specified.  Typically, | 
|---|
 | 90 | \fIservice\fR is the name of an application.  \fItopic\fR is application | 
|---|
 | 91 | specific but can be a command to the server or the name of a file to work | 
|---|
 | 92 | on.  The \fIitem\fR is also application specific and is often not used, but | 
|---|
 | 93 | it must always be non-null.  The \fIdata\fR field is given to the remote | 
|---|
 | 94 | application. | 
|---|
 | 95 | .TP | 
|---|
 | 96 | \fBdde request\fR ?\fB\-binary\fR? \fIservice topic item\fR | 
|---|
 | 97 | . | 
|---|
 | 98 | \fBdde request\fR is typically used to get the value of something; the | 
|---|
 | 99 | value of a cell in Microsoft Excel or the text of a selection in | 
|---|
 | 100 | Microsoft Word. \fIservice\fR is typically the name of an application, | 
|---|
 | 101 | \fItopic\fR is typically the name of the file, and \fIitem\fR is | 
|---|
 | 102 | application-specific. The command returns the value of \fIitem\fR as | 
|---|
 | 103 | defined in the application.  Normally this is interpreted to be a | 
|---|
 | 104 | string with terminating null.  If \fB\-binary\fR is specified, the | 
|---|
 | 105 | result is returned as a byte array. | 
|---|
 | 106 | .TP | 
|---|
 | 107 | \fBdde services \fIservice topic\fR | 
|---|
 | 108 | . | 
|---|
 | 109 | \fBdde services\fR returns a list of service-topic pairs that | 
|---|
 | 110 | currently exist on the machine. If \fIservice\fR and \fItopic\fR are | 
|---|
 | 111 | both empty strings ({}), then all service-topic pairs currently | 
|---|
 | 112 | available on the system are returned. If \fIservice\fR is empty and | 
|---|
 | 113 | \fItopic\fR is not, then all services with the specified topic are | 
|---|
 | 114 | returned. If \fIservice\fR is non-empty and \fItopic\fR is, all topics | 
|---|
 | 115 | for a given service are returned. If both are non-empty, if that | 
|---|
 | 116 | service-topic pair currently exists, it is returned; otherwise, an | 
|---|
 | 117 | empty string is returned. | 
|---|
 | 118 | .TP | 
|---|
 | 119 | \fBdde eval\fR ?\fB\-async\fR? \fItopic cmd \fR?\fIarg arg ...\fR? | 
|---|
 | 120 | . | 
|---|
 | 121 | \fBdde eval\fR evaluates a command and its arguments using the interpreter | 
|---|
 | 122 | specified by \fItopic\fR. The DDE service must be the \fBTclEval\fR | 
|---|
 | 123 | service.  The \fB\-async\fR option requests asynchronous invocation.  The | 
|---|
 | 124 | command returns an error message if the script did not run, unless the | 
|---|
 | 125 | \fB\-async\fR flag was used, in which case the command returns immediately | 
|---|
 | 126 | with no error.  This command can be used to replace send on Windows. | 
|---|
 | 127 | .SH "DDE AND TCL" | 
|---|
 | 128 | A Tcl interpreter always has a service name of \fBTclEval\fR.  Each | 
|---|
 | 129 | different interpreter of all running Tcl applications must be | 
|---|
 | 130 | given a unique | 
|---|
 | 131 | name specified by \fBdde servername\fR. Each interp is available as a | 
|---|
 | 132 | DDE topic only if the \fBdde servername\fR command was used to set the | 
|---|
 | 133 | name of the topic for each interp. So a \fBdde services TclEval {}\fR | 
|---|
 | 134 | command will return a list of service-topic pairs, where each of the | 
|---|
 | 135 | currently running interps will be a topic. | 
|---|
 | 136 | .PP | 
|---|
 | 137 | When Tcl processes a \fBdde execute\fR command, the data for the | 
|---|
 | 138 | execute is run as a script in the interp named by the topic of the | 
|---|
 | 139 | \fBdde execute\fR command. | 
|---|
 | 140 | .PP | 
|---|
 | 141 | When Tcl processes a \fBdde request\fR command, it returns the value of the | 
|---|
 | 142 | variable given in the dde command in the context of the interp named by the | 
|---|
 | 143 | dde topic. Tcl reserves the variable \fB$TCLEVAL$EXECUTE$RESULT\fR for | 
|---|
 | 144 | internal use, and \fBdde request\fR commands for that variable will give | 
|---|
 | 145 | unpredictable results. | 
|---|
 | 146 | .PP | 
|---|
 | 147 | An external application which wishes to run a script in Tcl should have | 
|---|
 | 148 | that script store its result in a variable, run the \fBdde execute\fR | 
|---|
 | 149 | command, and the run \fBdde request\fR to get the value of the | 
|---|
 | 150 | variable. | 
|---|
 | 151 | .PP | 
|---|
 | 152 | When using DDE, be careful to ensure that the event queue is flushed | 
|---|
 | 153 | using either \fBupdate\fR or \fBvwait\fR.  This happens by default | 
|---|
 | 154 | when using \fBwish\fR unless a blocking command is called (such as \fBexec\fR | 
|---|
 | 155 | without adding the \fB&\fR to place the process in the background). | 
|---|
 | 156 | If for any reason the event queue is not flushed, DDE commands may | 
|---|
 | 157 | hang until the event queue is flushed.  This can create a deadlock | 
|---|
 | 158 | situation. | 
|---|
 | 159 | .SH EXAMPLE | 
|---|
 | 160 | This asks Internet Explorer (which must already be running) to go to a | 
|---|
 | 161 | particularly important website: | 
|---|
 | 162 | .CS | 
|---|
 | 163 | package require dde | 
|---|
 | 164 | \fBdde execute\fR iexplore WWW_OpenURL http://www.tcl.tk/ | 
|---|
 | 165 | .CE | 
|---|
 | 166 | .SH "SEE ALSO" | 
|---|
 | 167 | tk(n), winfo(n), send(n) | 
|---|
 | 168 | .SH KEYWORDS | 
|---|
 | 169 | application, dde, name, remote execution | 
|---|