User Tools

Site Tools


how_to_start_a_dde_conversation.htm
Navigation:  How To's and Troubleshooting > How to… >====== How to Start a DDE Conversation ====== Previous pageReturn to chapter overviewNext page

DDE (Dynamic Data Exchange) is a Windows Inter-Process Communication (IPC) protocol. A DDE “conversation” consists of two applications trading messages. Within the DDE conversation, one application acts as the client, the other as the server.

The application which starts the conversation, requesting data or services from the other, is the client. The contacted application is the server. The server must “register” with Windows that it has server capability.

Clarion allows you to create both DDE clients and DDE servers. An application can be both. In fact, your application can act as both a client and server at the same time, though it requires two separate DDE conversations.

Starting a DDE conversation is as easy as using the DDECLIENT function. The only “catch” is that both applications must already be running to open the channel.

The simplest way to ensure that the conversation takes place at run time is to use an IF (conditional execution structure) structure. The DDECLIENT function returns zero if the server application isn't already running. Test its return value, and use the RUN statement to start the server app if it returns zero.

Many of the DDE procedures and functions require that you specify the DDE channel number, which is an integer that Windows returns when you open the DDE conversation. Create a local variable to hold the return value. Begin at the Procedure Properties dialog of the procedure you wish to contain the code for the DDE conversation.

To enable support for the DDE commands for your project or application, you must include the DDE.CLW file, located in the LIBSRC subdirectory.

Create a variable to hold the DDE channel number:

1.Open and select the IDE Data/Tables Pad. Select the procedure in the Application Tree that you wish to modify.

2.Highlight the Local Data section, and press the Insert AddTable.jpg button.

3.Type Channel in the Name field.

4.Choose LONG from the Type dropdown list.

5.Press the OK button to close the Field Properties dialog.

Initializing the Conversation

You must embed the code to initialize the DDE conversation, starting the server application if it's not already started. Assuming a menu choice in your application begins the conversation, embed the code at a field event associated with the Accepted menu choice.

1.Choose the appropriate field event in the Embedded Source list.

2.Press the Insert button.

3.Choose the Source item in the Select Embed Type dialog.

4.Type the following code, substituting the file name (without extension) of the Server application for “Excel.”

Channel = DDECLIENT('Excel','System')  ! Contact Excel re System topic

IF Channel <; 1                         ! If no contact made

 RUN('Excel')                         ! Attempt to start Excel

 Channel = DDECLIENT('Excel','System') ! And try again

ELSE

 RETURN                ! Give up if no contact - add error msg!

END

The code example is deliberately simplistic; it would be more efficient to LOOP through the attempt to contact twice, then warn the end user of the failure.

The code attempts to open a DDE conversation with Excel named as the server. The DDECLIENT function returns a value corresponding to the channel; it doesn't matter what the channel number is. If it's less than one, it failed. You must therefore start the server, and try to open the conversation again.

The second parameter of the DDECLIENT function is the DDE “Topic.” It tells the server what the DDE conversation is “about.” In most cases, the topic is a file name. In this case, the code names the “System” topic, which tells Excel the conversation is not regarding a particular document file.

how_to_start_a_dde_conversation.htm.txt · Last modified: 2021/04/15 15:57 by 127.0.0.1