7. Overview DDE

DDE is the abbreviation for Dynamic Data Exchange. DDE is a method of interprocess communication between programs to exchange data or control another program. Examples for DDE are querying a database, or sending data to a spreadsheet program. The application that intiates the conversation is the DDE client application; the application that responds to the client is the DDE server application. UniPlot can be used as a DDE server or client.

7.1. UniPlot as a Client

UniScript provides the following 6 functions for the client side. The user must define the functions.

  UniPlot as a Client
DdeInitiate DdeInitiate initiates a DDE conversation between UniPlot and another application.
DdeExecute DdeExecute executes a server macro.
DdePoke DdePoke sends data to a server.
DdeRequest DdeRequest retrieves data from a server.
DdeTerminate DdeTerminate terminates a DDE conversation.
DdeTerminateAll DdeTerminateAll closes all open DDE channels.

Example

Here is an example for UniPlot as client. The server is Excel:

system("c:/msoffice/excel/excel.exe", SW_HIDE, 1);
hConv = DdeInitiate("Excel", "System");
ssFile = GetRootDirectory() + "samples\map-data.xls";
DdeExecute(hConv, "[OPEN(\"" + ssFile + "\")]")
hConvTab = DdeInitiate("Excel", "map-data.xls");
ssData = DdeRequest(hConvTab, "z1s1:z16384s255");
DdeExecute(hConv, "[QUIT()]");
DdeTerminateAll();
hedit = EdCreate();
EdSetText(hedit, ssData);

The program excutes the following commands:

  • Excel will be started.
  • Excel will load the Samples\map-data.xls file.
  • Excel will send the sheet data to a UniPlot variable.
  • Teh content will be displayed in an UniPlot editor.

7.2. UniPlot as a Server

UniScript provides the following 6 functions calls for the server side. The user must define the functions.

  UniPlot as a Server
DdeCallback_Connect DdeCallback_Connect is called when a client wants to open a channel to UniScript.
DdeCallback_ConnectConfirm DdeCallback_ConnectConfirm is called after the DdeCallback_Connect function is called.
DdeCallback_Execute DdeCallback_Execute is called by the client, when a command in UniScript should be performed.
DdeCallback_Poke DdeCallback_Poke is called by the client to send data to UniPlot.
DdeCallback_Request DdeCallback_Request is called by the client to request data from UniPlot.
DdeCallback_Disconnect DdeCallback_Disconnect is called when the client closes the conversation.

Example

As an example we will write a Basic program for Microsoft Word. The Basic program will be used to create plots with UniPlot.

Lets start with the UniPlot side (Server). Copy the following code into a program editor in UniPlot and save the file on your computer. Press F4 to compile the function.

def DdeCallback_Poke(hConv, ssItem, ssTopic, ssData)
{
    ss = strtok(ssData, ",");
    rvData = strtod(ss);
    plot(1:len(rvData), rvData);
    return TRUE;
}

To keep the function short we have not checked and function parameters or return values.

Now lets start on the client side. Start Word and type in the following macro (Execute: Tools=>Macro=>Create Makro):

Sub Main
    chan = DDEInitiate("UniPlotSL", "xydata")
    DDEPoke chan, "xydata", "1, 5, 3, 4, 8, 12"
    DDETerminate(chan)
End Sub

If you execute the Basic function Main in Word, UniPlot will create a plot.

id-1535155