A Different DDE Application
Vector 12:4, page 116
Transcribed from the printed issue; not yet reviewed. Read it in the PDF of the issue, page 116
Regular readers will remember my diatribe on p.7 of Vol.11 No.4 concerning the mangling of Welsh grammar and spelling in an earlier issue. As a postscript I suggested (with some tongue in cheek) that it might be an idea for the Vector production team to obtain the new Welsh spell-checker from the Welsh Office, in Cardiff.
The version for Windows, called CySill, was released in August, 1995. Being interested in most things from west of Clawdd Offa (sorry, Offa’s Dyke), I ordered my copy and after a short while it arrived. I read the manual, and configured it to work with my word processor. As I read on, I came across a page headed "DDE Interface to CySill". Text is put into the clipboard, the spell-checker is called from another program via DDE, and the corrected text is then rescued from the clipboard and put back into your application. This sounded like an ideal opportunity to show that DDE is not restricted just to APL and the MS Office suite of programs, and that it will work with others as well.
When CySill is installed its directory must be included in the DOS path, so to start it up all you need is the name of its executable file, with no directory path. Only one instance of CySill can run at any one time: trying to start it a second time from the desktop just makes the existing instance active. This makes programming very much simpler because if we suspect that CySill is not already running we just try to start it up and if this fails we can’t go any further so we exit gracefully. Of course we could check to see if CySill is already running (see [2] for how) but there seems little point.
For the purposes of this exercise I have written some simple functions with lots of verbosity to enable me to see what’s happening. In any real application the functions would be much more terse. The ideas were obtained from Adrian Smith’s paper at APL93[1].
The algorithm I used is
Can we share with CySill?
If No then
Assume that CySill is not running so try to start it up
If the return from our start-up attempt implies that CySill is already running then
Exit gracefully
Can we share with CySill?
If No then
Exit gracefully
Put the text into the clipboard
Request CySill to check the text
Do until CySill has finished
Ask CySill if it has finished
Obtain the corrected text from the clipboard
Minimize CySill and wait for its next call.
The main function looks like this:
∇ z←Check z;CL;command;reply
[1] ⍝ Perform Welsh spell checking on the text in <z>
[2] →(2='DDE:CySill|archwilio'⎕SVO'command ±')/∆1
[3] 'CySill will not accept DDE. Maybe it is not running. Trying to start it up.'
[4] →(32<reply←StartMin'CYSWIN')/∆3
[5] →(16=reply)/∆3 ⍝ If we tried to start it a 2nd time
[6] 'Unable to start CySill, return code is ',⍕reply ⋄ →0
[7] ∆3:→(2='DDE:CySill|archwilio'⎕SVO'command ±')/∆1
[8] 'CySill will still not accept DDE!' ⋄ →0
[9] ∆1:'CL'⎕WC'Clipboard'
[10] 'CL'⎕WS'Text'z
[11] command←'GwirioClipboard'
[12] ∆2:→(0=reply←CySillRequest'Cyflwr')/finished
[13] →(0≠⍴,reply)/∆2
[14] 'You closed CySill before it finished. Cannot continue.' ⋄ →0
[15] finished:z←'CL'⎕WG'Text'
[16] ⍎('ie'≡CySillRequest'Cau')/'''You requested Close on the file menu.'''
[17] ⍎('na'≡CySillRequest'Newid')/'''No change.'''
[18] command←'Minimize' ⍝ Keep open for next time
∇
There are two called functions, one to make the DDE requests and the other to start up the application if it is not already running.
∇ z←CySillRequest x;y
[1] ⍝ Send a request to CySill and return its reply
[2] z←'' ⍝ Default if CySill is incommunicado
[3] →(2='DDE:CySill|archwilio'⎕SVO'y ',x)↓0
[4] z←y
∇
∇ z←StartMin x;WinExec
[1] ⍝ Start a Windows app. and minimize it, don't make it active
[2] ⎕NA'U kernel.exe.P16|WinExec <0T U'
[3] z←WinExec x 7
∇
In this last function I could have used z←⎕CMD x 'minimized', but this fails with a Domain Error if it can’t start CySill, rather than giving a return code to help you determine what is wrong.
There is no need to kill the task, because the chances are that having used it once you’ll need it again soon, so you might as well keep it alive.
Note that, unlike the applications in MS Office, you do not enclose the DDE commands to CySill in square brackets (in fact, if you do they will not be recognized!).
References¶
[1] Adrian Smith, Co-operative programming with Windows DDE, APL93 Conference Proceedings (APL Quote Quad, Vol.24, No.1) p.244.
[2] Duncan Pearson, A Windows Task-Killer for APL, Vector, Vol.10, No.2, p.126.
CySill, The Welsh spell-checker, is available from:
Welsh Language Board
Market Chambers
5-7 St Mary Street
Cardiff CF1 2AT
Telephone 01222-224744.