#################################################################
#
# This program is a sample DDE server that illustrates the
# simplest server processing possible. It accepts a single DDE
# conversation on the application/topic pair "Easel"/"sheet1.xls".
# The only item name for which it accepts requests is "r1".
#
# Note that this program can be used as a server partner for the
# sample client program on the previous page if the application
# names are made to match.
###################################
# Stimulus and Variable declarations
include esldde.inc # DDE library definitions stimulus DDE "esldde"
# DDE stimulus declaration
integer variable ConvID_IV is 0 # Conversation ID, supplied
# by DDE DLL
TempID_IV # for terminating extra
# conversations.
Status_IV # Conversation status flags
ErrorID_IV # ID of last error that
# occurred
DataLength_IV # For DDEDataString call boolean variable WildCard_BV is true
# For DDERegisterServer
string variable AppName_SV is "Easel" # Local (server)
# application name
Topic_SV is "sheet1.xls" # Conversation topic
ItemName_SV # Item name for data
# exchange
Format_SV # Format requested by
# client
DataString_SV # Buffer for data
###################################
# Primary Region Definition
enabled visible color 26 primary textual region PrimaryWindow_TR
size 500 200 at position 8 50
black foreground
title bar "Sample Easel DDE Server"
border
system menu
minimize button
maximize button
###################################
# Response Definitions
# Register one application/topic name pair, and then wait for a
# client to initiate a conversation.
response to start
call DDERegisterServer (AppName_SV, Topic_SV, WildCard_BV)
add to PrimaryWindow_TR insert "Waiting..."
# A client has asked for a conversation, and the DDE DLL has
# accepted on our behalf. Once the first conversation is
# established, this program terminates subsequent client
# initiations, as this program only handles a single conversation.
# (Note that this does not guarantee that the client did not issue
# any requests; if a request IS received from a partner that has
# been terminated, it should be ignored.)
response to stimulus DDE DDE_INITIATE
if (ConvID_IV = 0) then # First conversation
copy eventparam to ConvID_IV
add to PrimaryWindow_TR insert
"Initiate received, accepted\n"
else # Accept only 1 conversation
add to PrimaryWindow_TR insert
"\nanother initiate received, terminated\n"
copy eventparam_IV to TempID_IV
call DDETerminate (TempID_IV)
end if
# A client is requesting data; ignore requests from partners we
# have terminated. Otherwise, make sure we recognize the ITEM
# requested AND the format. If so, call DDEDataString to send the
# data. If not, allow the DDE DLL to perform its default
# processing, which is a negative acknowledgement.
response to stimulus DDE DDE_REQUEST
if (eventparam_IV = ConvID_IV) then #Ignore outdated requests
copy DDEGetItemName (ConvID_IV) to ItemName_SV
if (ItemName_SV = "r1") then # Check the item name
copy DDEGetFormat (ConvID_IV) to Format_SV
if (Format_SV = DDEFMT_TEXT) then # Check the format
copy "10 20 30\n" to DataString_SV
copy DDE_FRESPONSE to Status_IV
copy (length of DataString_SV) to DataLength_IV
add to PrimaryWindow_TR insert "request received,
data sent\n"
call DDEDataString (ConvID_IV, ItemName_SV,
DataString_SV, DataLength_IV,
Format_SV, Status_IV)
end if
end if
end if
# If the main conversation is being terminated, report it.
# Otherwise, this termination event is an acknowledgement for a
# terminate sent in the response to stimulus DDE DDE_INITIATE
# above.
response to stimulus DDE DDE_TERMINATE
if (eventparam_IV = ConvID_IV) then # Main conversation is
# being term'd
add to PrimaryWindow_TR insert
"Conversation terminated by partner\n"
copy 0 to ConvID_IV
end if
# Simply report errors to the screen, and terminate.
response to stimulus DDE DDE_ERROR
if (not (eventparam_IV = 0) then
copy DDEGetErrorID (eventparam_IV) to ErrorID_IV
add to PrimaryWindow_TR insert
"ERROR: " DDEGetErrorString (ErrorID_IV)
"; terminating conversation\n"
else
copy "ERROR: (Null Conversation ID Returned)
; terminating conversation\n"
end if
call DDETerminate (ConvID_IV)
# When the user closes the application, make sure all conversation
# are terminated.
response to PrimaryWindow_TR
on close
call DDETerminateAll ()
exit