dde(n)
β¨ NAME β¨
dde β Execute a Dynamic Data Exchange command π¦
okay so this is the dde(n) page, straight out of the Tcl Bundled Packages universe π
it's the one you want when your Tcl app needs to chat with other apps on Microsoft Windows. no cap.
πΈ SYNOPSIS πΈ
package require dde 1.4
dde servername ?-force? ?-handler proc? ?--? ?topic?
dde execute ?-async? ?-binary? service topic data
dde poke ?-binary? service topic item data
dde request ?-binary? service topic item
dde services service topic
dde eval ?-async? topic cmd ?arg arg ...?
π DESCRIPTION π
So this command lets an application send a Dynamic Data Exchange (DDE) command when it's running under Microsoft Windows πͺ Dynamic Data Exchange is the mechanism where applications can exchange raw data β it's giving walkie-talkie energy between programs.
Every single DDE transaction needs a service name and a topic π« Both of those are defined by the application itself, bestie β nobody's handing them to you. Tcl uses the service name TclEval, and the topic name is whatever name the interpreter was given by dde servername. Other applications have their own service names and topics, periodt. Like, for instance, Microsoft Excel has the service name Excel. π
π DDE COMMANDS π
The following commands are a subset of the full Dynamic Data Exchange set of commands. (yes, a subset β there's more DDE out there in the wild, but these are the ones Tcl hands you π«Ά)
π« dde servername ?-force? ?-handler proc? ?--? ?topic?
dde servername registers the interpreter as a DDE server with the service name TclEval and the topic name specified by topic. If no topic is given, dde servername returns the name of the current topic, or the empty string if it's not registered as a service. π
If the given topic name is already in use, then a suffix of the form β #2β or β #3β gets appended to the name to make it unique β the way that Tcl just casually slides a number in there π The command's result will be the name actually used, so check it.
-forceβ used to force registration of precisely the given topic name. no suffix, no negotiation, we're doing it exactly like this π-handlerproc β 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-handlerprocedure must be defined. The procedure is called with all the arguments provided by the remote call. π
β‘ dde execute ?-async? ?-binary? service topic data
dde execute takes the data and sends it to the server indicated by service with the topic indicated by topic. Typically, service is the name of an application, and topic is a file to work on. The data field is given to the remote application. Typically, the application treats the data field as a script, and the script is run in the application. π
-asyncβ requests asynchronous invocation. The command returns an error message if the script did not run, unless the-asyncflag was used, in which case the command returns immediately with no error. (so if you go async, you're not hearing about it, bestie π)
Without the -binary 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 -binary option in combination with the result of encoding convertto to send data in any other encoding. β¨
π dde poke ?-binary? service topic item data
dde poke passes the data to the server indicated by service using the topic and item specified. Typically, service is the name of an application. topic is application specific but can be a command to the server or the name of a file to work on. The item is also application specific and is often not used, but it must always be non-null β like, always, no exceptions, that's the vibe check π¨ The data field is given to the remote application.
Without the -binary 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 -binary option in combination with the result of encoding convertto to send data in any other encoding. πΈ
π₯ dde request ?-binary? service topic item
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, iykyk π service is typically the name of an application, topic is typically the name of the file, and item is application-specific. The command returns the value of item as defined in the application. Normally this is interpreted to be a string with terminating null.
-binaryβ if specified, the result is returned as a byte array. π§
π¦ dde services service topic
dde services returns a list of service-topic pairs that currently exist on the machine. Here's the whole tea β:
- If service and topic are both empty strings (
{}), then all service-topic pairs currently available on the system are returned. - If service is empty and topic is not, then all services with the specified topic are returned.
- If service is non-empty and topic is empty, 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 ?-async? topic cmd ?arg arg ...?
dde eval evaluates a command and its arguments using the interpreter specified by topic. The DDE service must be the TclEval service. π
-asyncβ requests asynchronous invocation. The command returns an error message if the script did not run, unless the-asyncflag was used, in which case the command returns immediately with no error. π
This command can be used to replace send on Windows. iconic behavior honestly.
π DDE AND TCL π
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. π do not touch that one, bestie, it is not yours.
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 then run dde request to get the value of the variable. that's the whole recipe, slay. π«Ά
π¨ THE BIG WARNING π¨ When using DDE, be careful to ensure that the event queue is flushed using eitherupdateorvwait. This happens by default when usingwishunless a blocking command is called (such asexecwithout 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. π no cap, that one will absolutely eat your afternoon.
β 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/
πΈ SEE ALSO πΈ
π KEYWORDS π
application, dde, name, remote execution
and that's the whole page, bestie π this one ships with Tcl Bundled Packages and it's version 1.4 β dde, 1.4, that's the one. go forth and exchange your data π¦β¨
π¦ where this page comes from
- alpine 3.23: tcl9-doc 9.0.3-r0 Β· TCL
- alpine 3.24: tcl9-doc 9.0.3-r2 Β· TCL
- fedora 43: tcl-doc 1:9.0.2-1.fc43 Β· TCL AND GPL-3.0-or-later WITH Bison-exception-2.2 AND BSD-3-Clause
- fedora 44: tcl-doc 1:9.0.2-1.fc44 Β· TCL AND GPL-3.0-or-later WITH Bison-exception-2.2 AND BSD-3-Clause
- nixos 26.05: tcl 9.0.3
- Copyright (c) 1997 Sun Microsystems, Inc
- Copyright (c) 2001 ActiveState Corporation
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms