ddeclientsample.ss
;This module provides examples for the use of ddeclient.ss
;Author: R. Matovinovic, 24.10.2006, v1.00
(module ddeclientsample mzscheme
  
  (require "ddeclient.ss")    
  
  (provide run)
  
  (define (run)
    ;info about version of dll
    (dc-dde-version)
    
    ;initialize DDEML.DLL for dde commands
    (dde-init)
    ;examples for request transactions
    (let* (;arguments for establishing connection
           (service "WinWord")
           (topic "system")
           ;arguments for DDE request command
           (conv (dde-connect service topic))  ;connect to service
           (type "request")       ;type of transaction
           (item "Sysitems")      ;item of request
           (data "")              ;data string used for poke transactions
           (format "CF_TEXT")     ;format of dde data between the applications
           (timeout 1000)            ;time in milliseconds when synchronous
           ;transaction finishes or 0 for asynchronous mode
           (access "byte")        ;data format how program accesses dde data
           ;variable for returned data and dde command
           (dde-data 0)
           )
      ;here is the general command for dde transactions this time for a request    
      (set! dde-data (dde-cmd conv type item data format timeout access))
      ;here you could do something with the returned data,
      ;this time they are only printed
      (printf "~nDde data of request transaction with dde-cmd:~n~a~n" dde-data)
      
      ;here is a more practical short version of the request command
      ;it returns a byte-string if data is returned
      (set! dde-data (dde-request conv item format timeout))
      ;here you could do something with the returned data,
      ;this time they are only printed as byte list.
      ;bytes->list only works with byte strings!
      (printf "~nDde data of request transaction with dde-request:~n~a~n" 
              (bytes->list dde-data))
      
      ;here is an even simpler request command for purely ascii text commands
      (set! dde-data (dde-request-string conv item timeout))
      ;here you could do something with the returned data,
      ;this time they are only printed
      (printf "~nDde data of request transaction with dde-request-string:~n~a~n"
              dde-data)
      
      ;disconnect after dde conversation
      (dde-disconnect conv)
      )
    
    (printf "~nThe following examples of execute and poke commands can ")
    (printf "only be checked for being sent but not for success.~n")
    
    ;example for execute transaction, short version with dde-execute
    ;opens a new file in winword
    (let* (;arguments for establishing connection
           (service "WinWord")
           (topic "system")
           ;arguments for DDE poke command
           (conv (dde-connect service topic)) 
           (item "[filenew]")     
           (timeout 0)
           )
      (dde-execute conv item timeout)
      ;there are no return data
      (printf "~nexecute [filenew] sent.~n")
      ;disconnect after dde conversation
      (dde-disconnect conv)
      )
    
    ;example for execute transaction, short version with dde-execute
    ;save the new file in winword as C:\test.doc
    (let* (;arguments for establishing connection
           (service "WinWord")
           (topic "system")
           ;arguments for DDE poke command
           (conv (dde-connect service topic)) 
           (item "[filesaveas \"C:\\test.doc\"]")     
           (timeout 0)
           )
      (dde-execute conv item timeout)
      ;there are no return data
      (printf "~nexecute [filesaveas \"C:\\test.doc\"] sent.~n")
      ;disconnect after dde conversation
      (dde-disconnect conv)
      )
    
    ;example for poke transaction, long version with dde-cmd
    (let* (;arguments for establishing connection
           (service "WinWord")
           (topic "C:\\test.doc")
           ;arguments for DDE poke command
           (conv (dde-connect service topic)) 
           (type "poke")      
           (item "\\EndOfDoc")     
           (data "Hello, this is 1. data from ddeclientsample. ")   
           (format "CF_TEXT")
           (timeout 0)
           (access "")
           )
      (dde-cmd conv type item data format timeout access)
      ;there are no return data
      (printf "~npoke sent.~n")
      ;disconnect after dde conversation
      (dde-disconnect conv)
      )  
    
    ;example for poke transaction, short version with dde-poke
    (let* (;arguments for establishing connection
           (service "WinWord")
           (topic "C:\\test.doc")
           ;arguments for DDE poke command
           (conv (dde-connect service topic)) 
           (item "\\EndOfDoc")     
           (data "Hello, this is 2. data from ddeclientsample. ")   
           (timeout 0)
           )
      (dde-poke conv item data timeout)
      ;there are no return data
      ;disconnect after dde conversation
      (dde-disconnect conv)
      )
    ;uninitialize DDEML.DLL
    (dde-uninit)
    )
)