Principles of DDE

The following describes how wxWindows implements DDE. The following three classes are crucial.

  1. wxClient. This represents the client application, and is used only within a client program.
  2. wxServer. This represents the server application, and is used only within a server program.
  3. wxConnection. This represents the connection from the current client or server to the other application (server or client), and can be used in both server and client programs. Most DDE transactions operate on this object.

Messages between applications are usually identified by three variables: connection object, topic name and item name. A data string is a fourth element of some messages. To create a connection (a conversation in Windows parlance), the client application sends the message MakeConnection to the client object, with a string service name to identify the server and a topic name to identify the topic for the duration of the connection. Under UNIX, the service name must contain an integer port identifier.

The server then responds and either vetos the connection or allows it. If allowed, a connection object is created which persists until the connection is closed. The connection object is then used for subsequent messages between client and server.

To create a working server, the programmer must:

  1. Derive a class from wxServer.
  2. Override the handler OnAcceptConnection for accepting or rejecting a connection, on the basis of the topic argument. This member must create and return a connection object if the connection is accepted.
  3. Create an instance of your server object, and call Create to activate it, giving it a service name.
  4. Derive a class from wxConnection.
  5. Provide handlers for various messages that are sent to the server side of a wxConnection.

To create a working client, the programmer must:

  1. Derive a class from wxClient.
  2. Override the handler OnMakeConnection to create and return an appropriate connection object.
  3. Create an instance of your client object.
  4. Derive a class from wxConnection.
  5. Provide handlers for various messages that are sent to the client side of a wxConnection.
  6. When appropriate, create a new connection by sending a MakeConnection message to the client object, with arguments host name (processed in UNIX only), service name, and topic name for this connection. The client object will call OnMakeConnection to create a connection object of the desired type.
  7. Use the wxConnection member functions to send messages to the server.