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

TDDEMLClient

TDDEMLClient connects to an existing DDE server, sends commands, and requests data.

Key DATA

DATATypeDescription
hInstNumericDDEML instance handle
hConvNumericConversation handle after successful connect
cServiceCharacterService name string
hServiceNumericService handle
cTopicCharacterTopic name string
hTopicNumericTopic handle
nTimeOutNumericTimeout in milliseconds for DDE operations

Key METHODs

MethodDescription
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

DATATypeDescription
hInstNumericDDEML instance handle
aClientsArrayArray of connected client conversation handles
bOnConnectBlockCodeblock evaluated when a client connects
bOnRequestBlockCodeblock evaluated when a client requests data; returns result
bOnDisconnectBlockCodeblock evaluated when a client disconnects
bOnExecuteBlockCodeblock evaluated when a client sends a command

Key METHODs

MethodDescription
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

Ver También