Skip to content
Tcl Source Code Artifact [2ed4a4a2eb]
Login

Artifact [2ed4a4a2eb]

Artifact 2ed4a4a2eb7864eadb9f30b10f1297871daf39615853e5f718ef258df8aad295:



CommandName: dde ManualSection: n Version: 1.4 TclPart: dde TclDescription: Tcl Bundled Packages Links:

Name

dde - Execute a Dynamic Data Exchange command

Synopsis

::: {.synopsis} ::: [package]{.cmd} [require]{.sub} [dde]{.lit} [1.4]{.lit}

[dde]{.cmd} [servername]{.sub} [-force]{.optlit} [[-handler]{.lit} [proc]{.arg}]{.optarg} [- -]{.optlit} [topic]{.optarg}

[dde]{.cmd} [execute]{.sub} [-async]{.optlit} [-binary]{.optlit} [service]{.arg} [topic]{.arg} [data]{.arg} [dde]{.cmd} [poke]{.sub} [-binary]{.optlit} [service]{.arg} [topic]{.arg} [item]{.arg} [data]{.arg} [dde]{.cmd} [request]{.sub} [-binary]{.optlit} [service]{.arg} [topic]{.arg} [item]{.arg} [dde]{.cmd} [services]{.sub} [service]{.arg} [topic]{.arg} [dde]{.cmd} [eval]{.sub} [-async]{.optlit} [topic]{.arg} [cmd]{.arg} [arg arg]{.optdot} :::

Description

This command allows an application to send Dynamic Data Exchange (DDE) command when running under Microsoft Windows. Dynamic Data Exchange is a mechanism where applications can exchange raw data. Each DDE transaction needs a fIservice namefR and a fItopicfR. Both the fIservice namefR and fItopicfR are application defined; Tcl uses the service name fBTclEvalfR, while the topic name is the name of the interpreter given by fBdde servernamefR. Other applications have their own fIservice namesfR and fItopicsfR. For instance, Microsoft Excel has the service name fBExcelfR.

Dde commands

The following commands are a subset of the full Dynamic Data Exchange set of commands.

dde servername ?fB-forcefR? ?fB-handlerfR fIprocfR? ?fB-|-fR? ?fItopicfR? : dde servername registers the interpreter as a DDE server with the service name fBTclEvalfR and the topic name specified by fItopicfR. If no fItopicfR is given, fBdde servernamefR returns the name of the current topic or the empty string if it is not registered as a service. If the given fItopicfR name is already in use, then a suffix of the form " #2" or " #3" is appended to the name to make it unique. The command's result will be the name actually used. The fB-forcefR option is used to force registration of precisely the given fItopicfR name. The fB-handlerfR option specifies a Tcl procedure that will be called to process calls to the dde server. If the package has been loaded into a safe interpreter then a fB-handlerfR procedure must be defined. The procedure is called with all the arguments provided by the remote call.

dde execute ?fB-asyncfR? ?fB-binaryfR? fIservice topic datafR : dde execute takes the fIdatafR and sends it to the server indicated by fIservicefR with the topic indicated by fItopicfR. Typically, fIservicefR is the name of an application, and fItopicfR is a file to work on. The fIdatafR field is given to the remote application. Typically, the application treats the fIdatafR field as a script, and the script is run in the application. The fB-asyncfR option requests asynchronous invocation. The command returns an error message if the script did not run, unless the fB-asyncfR flag was used, in which case the command returns immediately with no error. Without the fB-binaryfR option all data will be sent in unicode. For dde clients which don't implement the CF_UNICODE clipboard format, this will automatically be translated to the system encoding. You can use the fB-binaryfR option in combination with the result of fBencoding converttofR to send data in any other encoding.

dde poke ?fB-binaryfR? fIservice topic item datafR : dde poke passes the fIdatafR to the server indicated by fIservicefR using the fItopicfR and fIitemfR specified. Typically, fIservicefR is the name of an application. fItopicfR is application specific but can be a command to the server or the name of a file to work on. The fIitemfR is also application specific and is often not used, but it must always be non-null. The fIdatafR field is given to the remote application. Without the fB-binaryfR option all data will be sent in unicode. For dde clients which don't implement the CF_UNICODE clipboard format, this will automatically be translated to the system encoding. You can use the fB-binaryfR option in combination with the result of fBencoding converttofR to send data in any other encoding.

dde request ?fB-binaryfR? fIservice topic itemfR : dde request is typically used to get the value of something; the value of a cell in Microsoft Excel or the text of a selection in Microsoft Word. fIservicefR is typically the name of an application, fItopicfR is typically the name of the file, and fIitemfR is application-specific. The command returns the value of fIitemfR as defined in the application. Normally this is interpreted to be a string with terminating null. If fB-binaryfR is specified, the result is returned as a byte array.

dde services fIservice topicfR : dde services returns a list of service-topic pairs that currently exist on the machine. If fIservicefR and fItopicfR are both empty strings ({}), then all service-topic pairs currently available on the system are returned. If fIservicefR is empty and fItopicfR is not, then all services with the specified topic are returned. If fIservicefR is non-empty and fItopicfR is, all topics for a given service are returned. If both are non-empty, if that service-topic pair currently exists, it is returned; otherwise, an empty string is returned.

dde eval ?fB-asyncfR? fItopic cmdfR ?fIarg arg ...fR? : dde eval evaluates a command and its arguments using the interpreter specified by fItopicfR. The DDE service must be the fBTclEvalfR service. The fB-asyncfR option requests asynchronous invocation. The command returns an error message if the script did not run, unless the fB-asyncfR flag was used, in which case the command returns immediately with no error. This command can be used to replace send on Windows.

Dde and tcl

A Tcl interpreter always has a service name of fBTclEvalfR. Each different interpreter of all running Tcl applications must be given a unique name specified by fBdde servernamefR. Each interp is available as a DDE topic only if the fBdde servernamefR command was used to set the name of the topic for each interp. So a fBdde services TclEval {}fR command will return a list of service-topic pairs, where each of the currently running interps will be a topic.

When Tcl processes a fBdde executefR command, the data for the execute is run as a script in the interp named by the topic of the fBdde executefR command.

When Tcl processes a fBdde requestfR command, it returns the value of the variable given in the dde command in the context of the interp named by the dde topic. Tcl reserves the variable fB$TCLEVAL$EXECUTE$RESULTfR for internal use, and fBdde requestfR commands for that variable will give unpredictable results.

An external application which wishes to run a script in Tcl should have that script store its result in a variable, run the fBdde executefR command, and then run fBdde requestfR to get the value of the variable.

When using DDE, be careful to ensure that the event queue is flushed using either fBupdatefR or fBvwaitfR. This happens by default when using fBwishfR unless a blocking command is called (such as fBexecfR without adding the fB&fR to place the process in the background). If for any reason the event queue is not flushed, DDE commands may hang until the event queue is flushed. This can create a deadlock situation.

Example

This asks Internet Explorer (which must already be running) to go to a particularly important website:

package require dde
dde execute -async iexplore WWW_OpenURL http://www.tcl-lang.org/