Adding DDE Client Support

Do the following to provide DDE client support in your Windows or OS/2 application:

  1. Derive a class from IDDEClientConversation to provide implementations for all of the virtual callback functions in which you are interested. You must provide an implementation for the data pure virtual function.
  2. Create an object of the class you derived from IDDEClientConversation.
  3. Initiate a conversation with a DDE server application on a particular topic.
  4. Make requests for services from the DDE server. These transactions, or services, are usually requests for data, requests to accept data from you (poke data), or requests to execute commands on your behalf.
  5. Handle the responses to your requests that the DDE server sends you (in the virtual callback functions you have overridden).
  6. End the conversation with this DDE server application when you do not need any more services from this particular DDE server.
  7. Delete the object of the class derived from IDDEClientConversation or reuse the object and start over at item 3.

If you want to have multiple concurrent conversations, repeat the same procedure for each simultaneous conversation you need. Remember, although an IDDEClientConversation object represents a single conversation with a single server at any point in time, you can reuse the object for a subsequent conversation, after you have ended the current conversation.

Requesting a DDE Conversation

You can begin a DDE conversation in the following ways:

The begin function requires you to specify the name of the application you wish to have a conversation with, and the name of the topic you are interested in having a conversation about. For example:

bool bStarted = aConversation.begin( "Weather Server","Today's Forecast")

The begin function returns true if the IDDEClientConversation object succeeds in initiating a conversation with the requested application on the requested topic. If the IDDEClientConversation object is already in conversation on any topic, it will throw an IInvalidRequest exception. You can reuse the IDDEClientConversation object for a subsequent conversation once you have ended the current conversation.

The IDDEClientConversation class provides a second version of the begin function. Use this if you have already established a DDE conversation with another application, and you have an alternate method of exchanging the requisite window handles.

Requesting Data

To request data from a server application, use the requestData function. A server application can respond to a request for data in one of two ways:

In both cases, the following points are true:

Requesting a Data Hot Link

The DDE protocol supports ongoing links to data items, called hot links. Once you establish a hot link with a DDE server application for a particular data item, the server informs you whenever the value of the data changes. To request a hot link to a data item with a server application, you must use the beginHotLink function.

After you have established a data hot link, every time the value of the data item changes in the DDE server application, the following occurs:

  1. The server sends you the new value of the data item.
  2. The IDDEClientConversation object receives the updated data item, creates an IDDEDataEvent object, and passes a reference to this event when calling the data function.
Note: You can also use notification hot links. Every time the value of the data item changes in the DDE server application, the server sends a notification that the value of the data item has changed. When the IDDEClientConversation object receives the notification, it creates an IDDEClientHotLinkEvent object. You can then request the data when and if you need it.

Ending a Hot Link

Use IDDEClientConversation::endHotLink and IDDEClientConversation::endHotLinks to end hot links. To end a single hot link, call the endHotLink function, specifying the name of the data item and, optionally, the format of the data. For example, if you have multiple active hot links with a DDE server application on the Weather Corp data item, each in a different format, end one of the hot links as follows:

aConversation.endHotLink("Weather Corp", SZFMT_CPTEXT);

Use the endHotLinks function to end multiple hot links with one function call. There are two ways you can use this function:

  1. To end all of the hot links for all data formats of a particular data item, specify the name of the data item.
  2. To end all hot links for all data items and data formats for the IDDEClientConversation object, call endHotLinks with no parameters.

Poking Data

The DDE protocol introduces the concept of poking data from a DDE client application to a DDE server application. Poking data is essentially requesting a DDE server application to set a specified data item to a value passed by the client application. The IDDEClientConversation::pokeData member function sends a data poke request to the conversing DDE server application.

The IDDEClientConversation object throws an IInvalidRequest exception if it is not currently engaged in a conversation and the server application can respond to this request with either a positive or negative acknowledgment. In either case, the IDDEClientConversation object creates an IDDEAcknowledgePokeEvent object and passes a reference to this event by calling the pokeAcknowledged function.

Executing Remote Commands

The DDE protocol allows DDE client applications to send commands and command strings to DDE server applications for remote execution. Typically, you use this to send macros and commands to word processing or spreadsheet applications that support a command language and support this aspect of the DDE protocol. You can use IDDEClientConversation::executeCommands to send commands to DDE server applications.

Ending a Conversation

To end the current conversation, call the IDDEClientConversation::end. The IDDEClientConversation object first cleans up and then resets all of its object data to their original values when constructed.



For an example of how to set up a DDE client, refer to the \samples\ioc\dde\ddeclnt directory.


Dynamic Data Exchange


Adding DDE Server Support


IDDE
IDDEAcknowledgeEvent
IDDEActiveServer
IDDEBeginEvent
IDDEDataEvent
IDDEEndEvent
IDDEEvent
IDDEExecuteEvent
IDDEPokeEvent
IDDERequestDataEvent
IDDETopicServer