TDDEMLClient / TDDEMLServer
Sources: source/classes/tddemlcl.prg, source/classes/tddemlsv.prg
Standalone classes
The DDE Management Library (DDEML) classes provide a high-level interface to Windows Dynamic Data Exchange using the DDEML API. TDDEMLClient connects to DDE servers and executes commands or requests data; TDDEMLServer registers a DDE server that responds to client requests. Both classes handle conversation management, service/topic registration, and data transfer through the DDEML protocol.
flowchart LR
A["TDDEMLClient"] -->|Connect| B["DDE Server
TDDEMLServer"] A -->|Execute cCmd| B A -->|Request cReq| B B -->|_Return cData| A B -->|bOnConnect / bOnRequest| B
TDDEMLServer"] A -->|Execute cCmd| B A -->|Request cReq| B B -->|_Return cData| A B -->|bOnConnect / bOnRequest| B
TDDEMLClient
TDDEMLClient connects to an existing DDE server, sends commands, and requests data.
Key DATA
| DATA | Type | Description |
|---|---|---|
hInst | Numeric | DDEML instance handle |
hConv | Numeric | Conversation handle after successful connect |
cService | Character | Service name string |
hService | Numeric | Service handle |
cTopic | Character | Topic name string |
hTopic | Numeric | Topic handle |
nTimeOut | Numeric | Timeout in milliseconds for DDE operations |
Key METHODs
| Method | Description |
|---|---|
New() | Create DDE client and initialize DDEML |
Connect( cSvc, cTopic ) | Connect to a DDE server on the given service/topic |
Disconnect() | Terminate the DDE conversation |
Execute( cCmd ) | Send a command string to the server for execution |
Request( cReq ) | Request data from the server; returns result string |
NetConnect( cSvr, cApp ) | Connect to a DDE server on a remote network machine |
TDDEMLServer
TDDEMLServer registers as a DDE server, listening for client connections and responding to execute/request operations.
Key DATA
| DATA | Type | Description |
|---|---|---|
hInst | Numeric | DDEML instance handle |
aClients | Array | Array of connected client conversation handles |
bOnConnect | Block | Codeblock evaluated when a client connects |
bOnRequest | Block | Codeblock evaluated when a client requests data; returns result |
bOnDisconnect | Block | Codeblock evaluated when a client disconnects |
bOnExecute | Block | Codeblock evaluated when a client sends a command |
Key METHODs
| Method | Description |
|---|---|
New() | Create DDE server and initialize DDEML |
Connect() | Register the server's service name and start listening |
ConnectConfirm( hConv ) | Accept and confirm a client conversation |
Disconnect( hConv ) | Terminate a client conversation |
Execute( cCmd ) | Process a command sent by a client |
Request( cReq, cTopic ) | Handle a data request from a client; returns result string |
SetNetDDE( lOn ) | Enable or disable network DDE support |
_Return( cData ) | Return data to a client request; returns hData handle |
Example: Server and Client DDE
#include "FiveWin.ch"
// Server-side
function DdeServer()
local oServer := TDDEMLServer():New()
oServer:bOnConnect := { |hConv| ;
QOut( "Client connected: " + Str( hConv ) ) }
oServer:bOnRequest := { |cReq, cTopic| ;
"Server received: " + cReq }
oServer:bOnExecute := { |cCmd| ;
QOut( "Executing: " + cCmd ) }
oServer:Connect()
return oServer
// Client-side
function DdeClient()
local oClient := TDDEMLClient():New()
if oClient:Connect( "MyService", "MyTopic" )
oClient:Execute( "[SAVE]" )
? oClient:Request( "GetData" )
oClient:Disconnect()
endif
oClient:End()
return nil
Notes
- Both classes require the Windows DDEML library (USER32.DLL). Initialize with
DdeInitialize()and clean up withDdeUninitialize(). - The
Request()method on the client side returns a character string. On the server side,Request()should return the data to be sent, and_Return()packages it into a DDEML data handle. - Use
NetConnect()on the client to connect across machines via Network DDE (requires Network DDE to be enabled on both systems). - Server callback blocks receive the conversation handle as a parameter, allowing multi-client management via the
aClientsarray.