DDEApp, DDE Based Inter-process Communication (C#, C++)

This article discuss an inter-process communication protocol dedicated for sharing data and perform remote function call between applications.

Introduction

 

DDE Application (DDEApp) is a Dynamic Data Exchange (DDE) based inter-process communication protocol created to exchange data and perform functions call between applications.

Back in 2009, when I was still programming in Borland C++ Builder, I needed to find a solution to call function remotely between two applications. We had decided to make use of DDE for this purpose. Using VCL control in Borland, we managed to get DDE up within few days. However, soon we realized that existing DDE protocol was not able to fully meet our requirement.


About DDEApp

 

DDEApp a command line inter-process communication protocol implemented based on DDE. It contains a client and host class named as below.


C#
Borland C++
DDEApp Server
DDEAppServer
MDDEApp_Server
DDEApp Client
DDEAppClient
MDDEApp_Client

An overview of the classes is shown as below. DDEApp Client is designed to handle multiple clients.
Actual inter-process communication took place in DDE Server and Client class.

 

DDEApp Features

 

Hide low level settings from user

There are several parameters that need to be set correctly in DDE Server and Client class before two process can "talk" to each other using DDE. Client needs to know the server's setting upfront. User must figure out these settings either from code or documentation to establish DDE connection with Server.

DDEApp hide all DDE related parameters from user. User who use DDEApp did not need any knowledge with DDE. A standard sets of setting will be used for all DDEApp Server and Client instances. This means that all DDEApp Servers and Clients can communicate with each others.

Support multiple clients and servers

DDEApp Client and Server is designed to handle multiple clients and servers. A DDEApp Client can connect to multiple servers while a DDEApp Server is able to handle respond from multiple clients.

The diagram above shows that both Client A and C are connecting to more than 1 server while Server B have 3 clients connected to it. Besides, Server B also can be configure as Client to communicate with Server C at the same time being a server.


DDEApp Protocol

To ensure the correct message is passed between selected server and client, DDEApp implemented a command line message protocol which contains information of sender and receiver as below.

    <Source> <Dest> <Commands>
  • Source : Sender application's EXE name.
  • Dest: Receiver application's EXE name.
  • Commands: DDEApp commands
When using DDEApp class, we do not need to remember the command format. Encode and decode of the commands are done internally by DDEApp Client and Server class.
    A DDEApp Server is visible as virtual class to client application with list of registered functions and variables. Registered functions are accessible using FunctionCall() in DDEApp Client whereas registered variable are accessible from VariableRead() and VariableWrite() in DDEApp Client.

    Cross platform (C++ / C#)

    As an inter-process communication protocol, DDEApp allows application build from different platform (e.g. Borland Builder 5, Borland Builder 6, Visual C#) to communicate with each other. This is useful for mid to large scale projects when code conversion from one platform to another is time consuming and expensive.

    Standard functions 

    DDEApp Server included a list of common functions to remotely control the server's application.
    • Help
    • HideMainForm
    • RestoreWindow
    • MinimizeWindow
    • BringToFront
    • SetWindowPosition 

    Function lists

    The "Help" function shows above is an internal function created to return list of registered functions and variables from DDEApp Server. With this features, we are able to get most updated functions and variables list which may change from version to version. This is much better than any external documentation.

    Image below shows list of functions and variables in DDEApp Client terminal returned from a DDEApp enabled server application.



    Function call with error reporting

    All function call from DDEApp Client to DDEApp Server are made via FunctionCall(). Client will receive execution status upon completion of the functions. FunctionCall() is available in both synchronous and asynchronous version.

    Image below shows an example of DDEApp function call which return without error.
    Besides, it also shows additional info sent from DDEApp Server when executing function.

     This is another example shows failed function call which returned an error message.

    Variable Read / Write 

    Variable read or write are done in a similar way as function call except that variable are either read and write or just read only. Read or write to variable is synchronous call using VariableRead() and VariableWrite().

    Connect / Disconnect / Shut Down

    DDEApp Client can be connect or disconnect from DDEApp Server when required using function Connect() and Disconnect(). Server will get notify when a client is connected or disconnected.

    Besides, the client can request server to shut down using ShutDownServer() function. An OnClientShutdownQuery event will be raised at server application. Server has full authority to decide whether to proceed to shutdown itself.

    Online / Offline

    Online() and Offline() are two functions dedicated for DDEApp Server to enable or disable DDEApp protocol. When server is offline, none of the client is allowed to connect to the server. Any client that was connected earlier will received a OnLinkClosed event.


    DEMO and Tutorial


    NOTE:  DDE Application and C++ Library is compiled using Borland C++ Builder.
    If you were not able to run the executable file, pleas get the re-distributed library from below.


      Popular posts from this blog

      WinForms Gauge Control

      WinForms Controls

      C# DSP Simulation - DSP Lab