<< >> Title Contents Index


Dynamic Data Exchange (DDE)


Microsoft Windows makes it easy to exchange data between different applications. (The familiar clipboard is the simplest of these means.) Dynamic Data Exchange (DDE) is the most flexible method when there is a need to transfer data automatically.

DDE is a Microsoft Windows protocol that lets two or more programs running under Windows exchange data simultaneously. Windows for Workgroups has furthered DDEs reach by introducing the protocol into NetDDE communications, where getting black boxes to communicate with one another is often a struggle. NetDDE is a kind of universal super software glue. It lets MathViews cooperate with other Windows applications over the network. Thus enabling a building block approach to software.

DDE allows you to set up applications to pass both data and commands from one to the other. Normally one application requests the transfer and the other responds. The application that does the requesting is called the client application, and the application that responds is called the server. (This is not to be confused with the terms client and server as they are used internally within a database program or in a network of computers.) The information passing between client and server is called the conversation.

MathViews fully supports DDE both as a client and as a server. MathViews can pass commands to other applications, instructing them do such things as open files, select records, or transfer data to MathViews in various formats.

By "linking," you can arrange to have the other application inform MathViews whenever the linked data changes, or even have it automatically update MathViews whenever the linked data changes. Note that MathViews can be a DDE client and a DDE server simultaneously while still allowing you to perform normal user interface functions!

DDE Client/Server Conversations

A DDE conversation establishes a relationship between applications that require a sustained communication, in which both data and commands are passed repetitively for long periods. MathViews is capable of acting as either client or server, and can even act as client in one conversation and simultaneously act as server in another.

A typical conversation follows a standard pattern:

  1. Initiation. The client application initiates the conversation, and the server application responds.
  2. Exchange.Data is transferred. by one or more of the following methods:

    Client requests information. Server supplies information. (This is a "cold link." It does not provide for updating of the transferred data.) Client requests data and also requests to be notified whenever the data changes. Server supplies the data and also notifies client, without having to be asked again, whenever the data changes. (This is a "warm link." It allow updates, but only if, and when, the DDE client application approves the transfer.) Client requests data and also requests automatic updates whenever the data changes. Server supplies information and updates that data, without having to be asked again, whenever the data changes. (This is a "hot link." It ensure that any updates in the source data, made after the transfer is complete, are automatically and immediately changed in the DDE client application also.)

    Client successfully sends information, unsolicited, to the server. (This is a "poke.")

    Client requests server to issue a server-specific command. Server carries out the command. (When information is identified as a command, it is interpreted literally, as instructions rather than as data.)

  3. Termination. Either the client or the server terminates the conversation. The channel is closed and any links are ended.

    Because MathViews, and other advanced Windows applications are programmable, you will be able to write macros and programs which use specialized DDE commands to carry out these three activities.

MathViews as a DDE Client

If you want to transfer data dynamically from another application into MathViews, you make MathViews the DDE client. As described above, MathViews supports the three basic activities: Initiation, Exchange, and Termination.

These activities are supported by the five MathViews commands, which are described next. The "channel" over which the conversation takes place is "conv" in the syntax used by MathViews. Conv is a channel ID number. It must be obtain by the ddeconn command before any other commands can be used. The ID number is invalidated by the call to ddedisconn.

Commands

ddeconn initiate a DDE message exchange

Syntax: conv = ddeconn(server,topic)

Description: The argument, conv, is the ID of the channel you are establishing. The argument, server, must be a string. It is the DDE name (as defined by the application itself) of the application from which you are requesting data. The argument, topic, must be a string. It describes the information to be transferred. See the DDE section of the server application for a list of available topics.

Returns: conv, a positive number. In case of error the return value is 1.

ddereq request information from another application

Syntax: ddereq (conv,item)

Description: The argument, conv, must have already been obtained by call to ddeconn. The argument, item, must be a string. It describes the information desired from the server application. See the DDE section of the server application for a list of available items.

Returns: data

ddepoke send information to another application

Syntax: ddepoke (conv,item,data)

Description: The argument, conv, must have already been initiated by ddeconn. The argument, item, must be a string. It describes the location where the data is to be stored. The argument, data, is an expression containing the data to be sent. See the DDE section of the server application for a list of available items.

ddeexec send a command string to another application

Syntax: ddeexec (conv,command)

Description: The argument, conv, must have already been initiated by ddeconn. The argument, command, must be a string. It contains the command to be sent to the other application. Some target applications can accept a series of commands within command

ddedisconn terminate any DDE link and end the exchange

Syntax: ddedisconn (conv)

Description: The argument, conv, must have already been initiated by ddeconn. This call terminates the conversion/channel. You should not reference conv after this call.

Example

The following examples shows how MathViews might be used to establish a conversation with the Microsoft Excel spreadsheet. In this example, MathViews is the client and Excel is the server. Details on how to use Excel as a server are contained in the Excel documentation.

_loaddll mathvdde load the MathViews DDE library

!f:\excel\excel f:\excel\sheet1.xls have MathViews start the Excel application

hconvs=ddeconn('excel','System') name server (excel), conversation (through System)

hconv=ddeconn('excel','Sheet1.xls') name server (excel) and topic

x=ddereq(hconvs,'Formats') request information on formats

x=ddereq(hconv,'R3C4') request item

x=ddereq(hconv,'R3C2:R3C4') request another item

ddeadvise(hconv,'R3C4','x') request update or notification if change in item (link)

MathViews as a DDE Server

When MathViews is operating as the DDE server, the conversation is initiated by the other application, which acts as the client. The specific commands depend on the client's programming, but they should follow DDE conventions generally, and we shall assume here that they do.

Initiating a DDE Conversation

To set up a conversation with MathViews, the client must know the following things about MathViews: MathViews' application name (MathViews) A Topic name such as "MathViews."

After the channel is set up, there are four ways to pass information to MathViews:

Execute
A valid MathViews command can be passed to MathViews.
Poke
Data can be passed, unsolicited, to MathViews.
Request
The application can request data from MathViews.
Advise
The application can request updates or information on updates from MathViews.
Executing Commands
As stated above, any valid MathViews command can be passed from the client to MathViews.
Assigning Data by Poking
Sending unsolicited information to MathViews requires a set of data items. A data item, item, is a string that describes the location where the data is to be stored.
Requesting Data
The client may ask MathViews to send data from a data file. The request command must send the MathViews item string that describes the information to be transferred.
AdviseSetting up a Link
There are three kinds of links:
Cold links
do not provide for updating of the transferred data.
Warm links
allow updates, but only if and when the client approves the transfer.
Hot links
ensure that any updates in the source data, made after the transfer is completed, are automatically and immediately changed in the client application also.
Terminating a DDE Conversation
Use the terminate command of the client application, but give the MathViews application name and topic name in the arguments. Conversations must be terminated when no longer required. Terminating the conversation will also terminate any links that may have been set up during the conversation.

MathViews DDE Topics

MathViews supplies the following Topics support:

System
System Supports the following items:
Formats:
List of clipboard format numbers that the application can render.
Topics:
List of topics currently being supported.
SysItems:
List of system-topic items supported.
Status:
Busy or Ready, in response to a DDE request.
MathViews
The MathViews topic provides all variables supported by the MathViews application as items.

Example

The demo directory of MathViews contains an example of a Microsoft Excel macro to communicate with MathViews.

References

Maximizing Windows
Jim Boyce
Dynamic Data Exchange
New Writers Publishing

Windows Software Development Kit
Dynamic Data Exchange
Microsoft Corporation

Programing Windows
Charles Petzold
Microsoft Press

Windows Programming Guide To OLE/DDE
Jeffrey Clark
Sams


<< >> Title Contents Index