dde(3tcl)
β¨ NAME β¨
dde β Execute a Dynamic Data Exchange command π¦
okay so bestie, real quick housekeeping: this page is dde from the 3tcl manual, and it ships with the Tcl Bundled Packages π. So if you're on Windows and you wanna gossip between apps, you've come to the right girlie. Let's get into it.
π 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 π
This command lets an application send a Dynamic Data Exchange (DDE) command when it's running under Microsoft Windows πͺβ¨. DDE is the mechanism where applications can exchange raw data β like, it's giving middle-school note-passing but for processes, no cap.
Every single DDE transaction needs a service name and a topic. Both of those are defined by the application itself, which is the most "figure it out yourself" energy ever. Tcl uses the service name TclEval, and the topic name is the name of the interpreter, which you set with dde servername πββοΈ. Other applications bring their own service names and topics β for instance, Microsoft Excel rolls up with the service name Excel π
π DDE COMMANDS π
These are a subset of the full Dynamic Data Exchange command set. Not the whole buffet, just the good plates π.
dde servername ?-force? ?-handler proc? ?--? ?topic?
dde servername registers the interpreter as a DDE server with the service name TclEval and the topic name you give it in topic πΈ.
If you don't hand it a topic, dde servername returns the name of the current topic β or the empty string if it's not registered as a service at all. Awkward but honest.
If the topic name you asked for is already taken, a suffix of the form β #2β or β #3β gets appended to make it unique π’. The command's result will be the name actually used, so check it, don't assume.
-forceβ forces registration of precisely the given topic name. No suffix negotiations, you said what you said π-handlerβ specifies a Tcl procedure that will be called to process calls to theddeserver. 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 β yeah, all of them, the whole group chat gets forwarded π¨
dde execute ?-async? ?-binary? service topic data
dde execute takes 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 gets handed to the remote application, which typically treats it like a script and just runs it. Very "here's a note, do something with it" π.
-asyncβ requests asynchronous invocation. The command returns an error message if the script did not run β unless the-asyncflag was used, in which case it returns immediately with no error. So if you go async, you're not getting the tea back. It's giving ghosting, respectfully π»
Without the -binary option, all data is sent in unicode. For dde clients that don't implement the CF_UNICODE clipboard format, this will automatically be translated to the system encoding. And you can use -binary in combination with the result of encoding convertto to send data in any other encoding π§ β slay.
dde poke ?-binary? service topic item data
dde poke passes the data to the server indicated by service, using the topic and item you 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, periodt. The data field is given to the remote application.
Without the -binary option, all data will be sent in unicode. For dde clients that don't implement the CF_UNICODE clipboard format, this will automatically be translated to the system encoding. You can use -binary 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 β like the value of a cell in Microsoft Excel, or the text of a selection in Microsoft Word ππ.
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 a terminating null. But if -binary is 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 π. And the rules for what you get back are very specific, so listen up:
- If both service and topic are 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, then all topics for a given service are returned.
- If both are non-empty, and 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.
Heads up bestie: the DDE service must be the TclEval service. No substitutions, no exceptions.
-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 behaviour honestly.
π DDE AND TCL π
A Tcl interpreter always has a service name of TclEval. Every different interpreter across all your running Tcl applications must be given a unique name, which you set with 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 that interp So a dde services TclEval {} command will return a list of service-topic pairs, and each of the currently running interps will show up as 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's Tcl's personal diary, okay bestie?
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 π‘.
β οΈ 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 π. Not the vibe. Flush your queue, queen.
π§ EXAMPLE π§
This asks Internet Explorer (which must already be running, ok?) 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 was all about dde, version 1.4, straight out of the Tcl Bundled Packages in the dde(3tcl) manual π«Άβ¨ go forth and exchange your dynamic data, iykyk π
π¦ where this page comes from
- ubuntu stonking: tcl9.0-doc 9.0.4+dfsg-1
- 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