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
DATA Type Description
nServiceNumeric Global atom for the service name
nTopicNumeric Global atom for the topic name
oWndServerObject Server window object after connection
lActiveLogical .T. when DDE conversation is active
Methods
Method Description
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
DATA Type Description
oWndObject Main window object for message handling
cServiceCharacter Service name (converted to atom)
cTopicCharacter Topic name (converted to atom)
lActiveLogical .T. when DDE conversation is active
nAckNumeric ACK status: 0=OK, 1=Busy, 2=NotSupported, 3=Timeout
cDataCharacter Holds data received from a Request call
Methods
Method Description
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
DATA Type Description
oWndObject Main window object for message handling
cServiceCharacter Service name to respond to
cTopicCharacter Topic name to respond to
bInitBlock Code block executed on DDE initiate (return .F. to reject)
bExecuteBlock Code block executed on DDE_EXECUTE
bRequestBlock Code block executed on DDE_REQUEST (return data string)
bPokeBlock Code block executed on DDE_POKE
Methods
Method Description
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
DDE uses Windows messaging (WM_DDE_*) and global atoms for service/topic identification.
The server window must remain alive for the conversation to stay active. Server activation happens automatically when New() wires the handlers.
ACK codes are: 0=OK, 1=Busy, 2=NotSupported, 3=Timeout. Check ::nAck after each operation.
For Request(), the returned data is stored in ::cData. Only CF_TEXT is supported.
See Also ← tdbodbcdirect | tddeclient →