TDde / TDdeClient / TDdeServer

Sources: source/classes/dde.prg, source/classes/ddeclien.prg, source/classes/ddeserv.prg

Standalone classes (not control-based)

These three classes implement Dynamic Data Exchange (DDE) communication between Windows applications. TDde is a simplified DDE wrapper, while TDdeClient and TDdeServer provide a more complete client-server implementation with support for Execute, Request, Poke, and acknowledgment handling.

TDde (Simple DDE)

Key DATA Members

DATATypeDescription
nServiceNumericGlobal atom for the service name
nTopicNumericGlobal atom for the topic name
oWndServerObjectServer window object after connection
lActiveLogical.T. when DDE conversation is active

Methods

MethodDescription
New( cService, cTopic, cItem, bAction, bEnd )Create a DDE object with service, topic, item atoms and action/end code blocks
Activate()Broadcast WM_DDE_INITIATE to all top-level windows
Execute( cCommand )Send a DDE execute command to the server
End()Terminate the DDE conversation and delete atoms

TDdeClient (Full Client)

Key DATA Members

DATATypeDescription
oWndObjectMain window object for message handling
cServiceCharacterService name (converted to atom)
cTopicCharacterTopic name (converted to atom)
lActiveLogical.T. when DDE conversation is active
nAckNumericACK status: 0=OK, 1=Busy, 2=NotSupported, 3=Timeout
cDataCharacterHolds data received from a Request call

Methods

MethodDescription
New( oWnd, cService, cTopic )Create client; wires bDDE_ACK and bDDE_DATA to the window
Activate( nWait )Send WM_DDE_INITIATE; optionally wait nWait seconds for ACK
Execute( cCommand, nWaitOK )Send a command string and optionally wait for confirmation
Request( nType, cCommand, nWaitOK )Request data from the server (CF_TEXT default); result in ::cData
Poke( nType, cItem, cData, nWaitOK )Send data to the server identified by cItem
End()Terminate conversation and delete atoms

TDdeServer (Full Server)

Key DATA Members

DATATypeDescription
oWndObjectMain window object for message handling
cServiceCharacterService name to respond to
cTopicCharacterTopic name to respond to
bInitBlockCode block executed on DDE initiate (return .F. to reject)
bExecuteBlockCode block executed on DDE_EXECUTE
bRequestBlockCode block executed on DDE_REQUEST (return data string)
bPokeBlockCode block executed on DDE_POKE

Methods

MethodDescription
New( oWnd, cService, cTopic, bInit, bExecute, bRequest, bPoke, bTerminate )Create server and wire DDE message handlers to window
End()Remove message handlers and mark inactive

Example: DDE Client

#include "FiveWin.ch"

function DDEClientDemo()

   local oClient := TDdeClient():New( oWnd, "MyService", "MyTopic" )

   // Activate with 5-second timeout
   if oClient:Activate( 5 )
      // Execute a command
      oClient:Execute( "OPEN_FILE|C:\data.txt" )
      // Request data
      oClient:Request( 1, "GET_STATUS" )
      MsgInfo( oClient:cData )
      oClient:End()
   endif

return nil

Example: DDE Server

#include "FiveWin.ch"

function DDEServerDemo( oWnd )

   local oServer := TDdeServer():New( oWnd, "MyService", "MyTopic",;
      {|cSrv,cTop| MsgInfo( "Client connected: "+cSrv ), .T. },;
      {|cCmd|   MsgInfo( "Exec: " + cCmd ), .T. },;
      {|cItem|  If( cItem == "TIME", Time(), "" ) },;
      {|cItem,cData| MsgInfo( "Poked: "+cItem+"="+cData ), .T. } )

return nil

Notes

Ver También