DDE Command v1.6

Introduction

This is a command line (aka console) based tool for querying text data from DDE servers. It is the counterpart to my much older GUI based tool called DDE Query.

Commands

The tool supports all the major DDE command types, such as XTYP_REQUEST, XTYP_ADVSTART, XTYP_POKE & XTYP_EXECUTE via similarly named commands. The basic format for invoking DDE Command is to run it with a command type and then provide any arguments using switches, e.g.

C:\> ddecmd command --option1 value1 --option2 value2

The arguments can be specified using either Windows style (e.g. /option) or the more modern style (e.g. --option). Each switch has both a short name and a longer name and you can see the list of all supported commands using "ddecmd --help". Each command has its own help topic that describes itself and lists the switches that are applicable, e.g. ddecmd request --help.

The Servers Command

This command invokes the XTYP_WILDCONNECT transaction type to list the running DDE servers and their supported topics. This transaction type is not always supported by servers and is included more for development use. The output is one server and topic per line, separated by a '|', the normal separator used for DDE Links, e.g.

C:\> ddecmd servers
Excel|System
Excel|[Book1]Sheet3
Excel|[Book1]Sheet2
Excel|[Book1]Sheet1

The Request Command

The request command is used to retrieve the value for one or more items from the server. This is the XTYP_REQUEST transaction type. The items must all be from the same server as only a single server and topic can be specified.

C:\> ddecmd request --server REUTER --topic IDN_RWS --item "GBP=,BID ASK" --item "EUR=,BID ASK"
+1.9058 +1.9062
+1.2981 +1.2982

By default the request assumes CF_TEXT (i.e. ANSI text) for the value format, but this can be overridden by using the --format switch. See below for the format names.

When a single item is requested the output is just the value by itself. When multiple items are requested each value is prefixed by the item name. For complete control over the display format use the --output-format switch which is detailed later, e.g.

C:\> ddecmd request --server REUTER --topic IDN_RWS --item "GBP=,MID" --output-format "%d %i -> %v"
2010-02-01 22:32:15 GBP=,MID -> +1.9058

Excel provides another way of expressing a DDE link that is more compact. The --link switch can be used instead of specifying the server, topic and item separately, e.g.

C:\> ddecmd request --link "REUTER|IDN_RWS!GBP=,BID ASK"
+1.9058 +1.9062

Note: You can currently only specify a single item with the --link switch because it includes the server and topic, and only a single conversation is currently supported.

The Advise Command

To set up one or more advise loops with the server use the advise command. This allows you to monitor the updates for a number of items and corresponds to the XTYP_ADVSTART & XTYP_ADVDATA transaction types. The same basic switches that are used with the Request command can also be used with this one. However, unlike the other commands, this causes ddecmd to run indefinitely and so can only be stopped by pressing Ctrl+C.

C:\> ddecmd advise -s REUTER -t IDN_RWS -i "GBP=,BID ASK" -i "EUR=,BID ASK"
+1.9060 +1.9062
+1.2981 +1.2986
+1.2980 +1.2982
+1.9059 +1.9064
+1.2978 +1.2983
+1.2982 +1.2984
+1.9059 +1.9062
<CTRL+C>

The Poke Command

The poke command allows you to set a value for an item on servers that support it (XTYP_POKE). Unlike the previous request and advise commands you can only set the value for a single item and that value will be passed in CF_TEXT format, e.g.

C:\> ddecmd poke -s excel -t [book1]sheet1 -i R1C1 --value "test"

Note: The Poke command also supports the --link switch as described earlier.

The Execute Command

The final transaction type supported is XTYP_EXECUTE via the execute command. This is used to send a command string to a server, e.g.

C:\> ddecmd execute -s excel -t [book1]sheet1 --command "[App.Minimize]"

Note: The command doesn't support the --format switch because the DDE transaction type XTYP_EXECUTE ignores it. Consequently the command is always sent in CF_TEXT for an ANSI build and CF_UNICODETEXT for a Unicode build. This is to work around an apparent bug in Windows/DDEML that shows up when sending a CF_TEXT format command from a Unicode DDE client to an ANSI DDE server.

The Listen Command

The previous commands have all been for acting as as DDE client. The listen command however is for acting as a DDE server. Its use is intended for testing DDE clients as it just logs the interactions made by a DDE client with it, e.g.

C:\> ddecmd listen -s TestServer
XTYP_CONNECT: 'TestServer', 'TestTopic'
XTYP_CONNECT_CONFIRM: 'TestServer', 'TestTopic'
XTYP_REQUEST: 'TestServer', 'TestTopic', 'TestItem', '1'
XTYP_DISCONNECT: 'TestServer', 'TestTopic'
<CTRL+C>

The only additional switch supported is --delay which causes the DDE server to pause before replying to simulate a slow-running server.

The Fetch Command

This command is not a native DDE transaction type but a hybrid that combines the XTYP_ADVSTART and XTYP_REQUEST transactions to request a value in much the same way as Excel links to data. The delay between the two DDE transactions is configurable but defaults to 0 ms.

C:\> ddecmd fetch -s excel -t [book1]sheet1 -i R1C1

Note: This command was added specifically to cater for the MetaTrader DDE Server which fails an XTYP_REQUEST with N/A unless an XTYP_ADVSTART has already been invoked on the item.

Transaction Timeouts

The default timeout for any DDE transaction is set to 30,000 ms (30 secs). If your DDE server is slow at returning responses you might receive one of the DDE timeout errors - DMLERR_DATAACKTIMEOUT, DMLERR_EXECACKTIMEOUT, etc. You can increase the timeout for any transaction (except the servers command) with the --timoeut switch, e.g.

C:\> ddecmd execute -s excel -t [book1]sheet1 -c "[App.Minimize]" --timeout 60000

Clipboard Formats

The table below lists the common formats (i.e. text based) that you can request with the --format switch.

FormatDescription
CF_TEXTANSI text
CF_UNICODETEXTUnicode text

Output Format

The table below lists the variables can be used within the --output-format switch. To include a '%' character in the output you need to escape it with another '%', just as you would in a batch file, e.g. '%%'. All other characters in the string are output verbatim.

VariableDescription
%sThe name of the DDE service
%tThe name of the DDE topic
%iThe name of the DDE item
%vThe value of the DDE item
%dThe timestamp of when the value was received

For example, if an advise loop is started for a link SERVICE|TOPIC!ITEM with the --output-format specified as "%d: (%s,%t,%i) = %v", the output might look like this:-

2013-02-01 17:33:45: (SERVICE,TOPIC,ITEM) = 42.0

Note: If you are executing commands from within a batch file you need to remember to escape the '%' characters with another '%'. So the example above would then become "%%d: (%%s,%%t,%%i) = %%v". That also means to escape a single literal '%' in the format string would require the sequence '%%%%'!

Timestamp Format

The '%d' variable that can be used in the --output-format switch causes a timestamp to be output. As shown in the example above it defaults to the ISO format "YYYY-MM-DD HH:MM:SS". However the format can be customized with the --date-format and --time-format switches. The format strings are effectively passed directly to the GetDateFormat() and GetTimeFormat() Windows API functions. To avoid either the date or time being output at all specify an empty format, e.g. --time-format "".

This table lists the place-holders that can be used in the date picture format.

TypeDescription
dDay of month as digits with no leading zero for single-digit days
ddDay of month as digits with leading zero for single-digit days
dddDay of week as a three-letter abbreviation
ddddDay of week as its full name
MMonth as digits with no leading zero for single-digit months
MMMonth as digits with leading zero for single-digit months
MMMMonth as a three-letter abbreviation
MMMMMonth as its full name
yYear as last two digits, but with no leading zero for years less than 10
yyYear as last two digits, but with leading zero for years less than 10
yyyyYear represented by full four digits
ggPeriod/era string

This table lists the place-holders that can be used in the time picture format.

TypeDescription
hHours with no leading zero for single-digit hours; 12-hour clock
hhHours with leading zero for single-digit hours; 12-hour clock
HHours with no leading zero for single-digit hours; 24-hour clock
HHHours with leading zero for single-digit hours; 24-hour clock
mMinutes with no leading zero for single-digit minutes
mmMinutes with leading zero for single-digit minutes
sSeconds with no leading zero for single-digit seconds
ssSeconds with leading zero for single-digit seconds
tOne character time-marker string, such as A or P
ttMulti-character time-marker string, such as AM or PM


License & Warranty

This application is freeware - you get what you pay for, nothing more, nothing less.

Source Code

The full source code (C++) is available from my web site listed below.

Contact Details

Using the --version switch will also display my contact details. Please check the web site for updates.

Email: gort@cix.co.uk
Web: www.chrisoldwood.com

Chris Oldwood
13th January 2017