Dynamic Data Exchange (DDE)

Project: A DDE-enabled PC application, such as Excel, Access or Visual Basic, has a need to interact with a host session to communicate with a host application. A minimal implementation would require the ability to get a screen capture of what is currently displayed in the session, and to send characters or keystrokes to the session.

Algorithm: DDE support in DynaComm is implemented via script, whether as a DDE Client or DDE Server. In this example, DynaComm responds to commands made by another PC application, so appropriate DDE Server functionality needs to be implemented. To support the command for screen capture retrieval, a DDE Request function is enabled with the (DDE) WHEN REQUEST command so the script will respond to incoming DDE Requests. To support sending of data to the session, a DDE Poke function is enabled with a (DDE) WHEN POKE command so the script will recognize incoming DDE Pokes.

To make use of the functionality implemented by this script, the DDE Client application must use DDE Request and Poke commands in syntax appropriate to that application. The process, in general, is that the DDE Client uses an INITIATE or ACCESS command to establish a DDE conversation with the DDE Server, and then uses commands supported by the DDE Server. These commands typically require use of three parameters: server, topic, and item. In DynaComm, the Server is the name of th/support/index.htme main executable, the topic is the name of your script supporting DDE functionality, and the item is a parameter specified in the script.

Relevant Commands and Functions:

DDE Server commands and functions:

(DDE) WAIT SIGNAL — Pauses script execution until next DDE command is received
(DDE) WHEN ADVISE — Activates when a DDE Advise or DDE Unadvise is received
(DDE) WHEN EXECUTE — Activates when a DDE Execute/Instruct is received
(DDE) WHEN INITIATE — Activates when a DDE Initiate/Access is received
(DDE) WHEN POKE — Activates when a DDE Poke is received
(DDE) WHEN REQUEST — Activates when a DDE Request is received
(DDE) WHEN TERMINATE — Activates when the current DDE conversation is terminated
(DDE) TABLE REPLY — Sends a table to a DDE Client in response to a DDE Advise or Request
(DDE) ADVISE( ) — Indicates if WHEN ADVISE was triggered by a DDE Advise or DDE Unadvise command

See Also:

SHOW — Display each script command as it is executed.

DDE Client commands (not used in this example):

(DDE) ACCESS — Initiates a DDE conversation with a DDE Server
(DDE) ACCESS CANCEL — Terminates an active DDE conversation
(DDE) INSTRUCT — Sends a string of commands to DDE Server
(DDE) POKE — Sends a string to the DDE Server
(DDE) REQUEST — Requests a single data item from DDE Server
(DDE) TABLE REQUEST — Requests data table in specified format from DDE Server
(DDE) TABLE SEND — Sends the specified table to the DDE Server

A Brief Example


WHEN POKE 1 TABLE 2 %Channel "SendKeys"
$Data = TRIM(@R2.1)

WHEN REQUEST 1 %Channel "ScreenCapture"
WAIT QUIET "00:00:01"
%Line = 0
WHILE(%line < 24)
@R2.1 = SCREEN(%line, 0, 80,ACTIVE())

TABLE REPLY 2 TO %channel "ScreenCapture"



In this example, DynaComm is set up as a DDE Server which responds to commands and/or requests made by applications operating as a DDE Client. Specifically, this script supports the ability of a DDE Client to send characters to the active host session, or to request the data displayed in the session window. To make use of the functionality to send characters, the DDE Client performs a DDE Poke operation where the Item is “SendKeys”, since that is the syntax supported on the WHEN POKE line of this script. To make use of the functionality to retrieve the data from the screen, the DDE Client performs a DDE Request operation where the Item parameter is “ScreenCapture” since that is the syntax supported above, on the WHEN REQUEST line of our script. Additional Poke or Request functionality could be supported by this script by adding up to 15 more WHEN POKE commands and up to 15 more WHEN REQUEST lines, with user defined Item names and functionality.

The structure of the script above is much like the Event Monitoring example, in that there are several WHEN commands with associated command blocks to be performed when events happen. After initialitizing a few values, the script waits at a WHILE TRUE WAIT SIGNAL loop, which waits for DDE commands from other applications. When a Poke is received which matches the Item name of “SendKeys”, the data is received into Table 2, has trailing space characters trimmed and is sent to the session if connected. When a Request is received with the Item name of “ScreenCapture”, a loop scrapes data off the screen, writes it to a Table, and does a TABLE REPLY to send that table to the Requesting application.

Further Development:

  • If the DDE Client needed data from particular regions of the screen, but not the whole session, individual WHEN REQUESTS could be set up to serve those independent requests.
  • The script could automatically send an updated screen capture to the DDE Client whenever the session display changes. See the WHEN ADVISE command.
  • The addition of WHEN EXECUTE commands to the script could enable the DDE Client to direct activities in the host session, such as disconnecting the session, logging off, activating or hiding the session.
  • With additional WHEN REQUEST commands, the script could support status reporting features, enabling the DDE Client to query the status of the session and the host.
  • DDE supports up to 16 concurrent conversations. Most of the commands also have a limit of 16 concurrent, indicated by the optional Index parameter which takes values 0 through 15. Using the WHEN REQUEST or WHEN POKE commands with an index of 16 allows them to respond to a Request or Poke which does not match any of the specified WHEN REQUEST or WHEN POKE commands.

Additional Examples:

The DDECLNT example demonstrates DDE Client functionality to any DDE Server. User inputs all the parameters, initiates the conversation, does Pokes, Requests, Executes. Can be used with the DDESERV example script mentioned below, using the parameters defined in DDESERV.

The DDESERV example Exhibits DDE Server functionality similar to this project, includes several WHEN EXECUTE illustrations too.