dde(n) | Tcl Bundled Packages | dde(n) |
dde - Execute a Dynamic Data Exchange command
package require dde 1.3
dde servername ?-force? ?-handler proc? ?--? ?topic?
dde execute ?-async? service topic data
dde poke service topic item data
dde request ?-binary? service topic item
dde services service topic
dde eval ?-async? topic cmd ?arg arg ...?
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 service name and a topic. Both the service name and topic are application defined; Tcl uses the service name TclEval, while the topic name is the name of the interpreter given by dde servername. Other applications have their own service names and topics. For instance, Microsoft Excel has the service name Excel.
The following commands are a subset of the full Dynamic Data Exchange set of commands.
The -handler 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 -handler procedure must be defined. The procedure is called with all the arguments provided by the remote call.
A Tcl interpreter always has a service name of TclEval. Each different interpreter of all running Tcl applications must be given a unique name specified by dde servername. Each interp is available as a DDE topic only if the dde servername command was used to set the name of the topic for each interp. So a dde services TclEval {} command will return a list of service-topic pairs, where each of the currently running interps will be a topic.
When Tcl processes a dde execute command, the data for the execute is run as a script in the interp named by the topic of the dde execute command.
When Tcl processes a dde request 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 $TCLEVAL$EXECUTE$RESULT for internal use, and dde request 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 dde execute command, and the run dde request to get the value of the variable.
When using DDE, be careful to ensure that the event queue is flushed using either update or vwait. This happens by default when using wish unless a blocking command is called (such as exec without adding the & 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.
This asks Internet Explorer (which must already be running) to go to a particularly important website:
package require dde dde execute iexplore WWW_OpenURL http://www.tcl.tk/
tk(n), winfo(n), send(n)
application, dde, name, remote execution
1.3 | dde |