Version 1 of winsend

Updated 2002-04-08 21:18:47

The winsend package is an attempt to implement the Tk send command under MS Windows using COM to handle the registration and interprocess communication for us. When loaded into an interpreter the package will automatically register in the system's running object table. The winsend interps command can be used to show all the registered interpreters and unlike using dde this command will not be blocked by badly behaving windows applications.

 An example (from tkcon):         from a concurrent tclsh:
   % package require winsend  |     % package require winsend
   0.4                        |     0.4
   % winsend interps          |     % winsend interps
   tkcon.tcl                  |     tkcon.tcl TCLSH.EXE
                              |     % winsend send tkcon.tcl set x 1
                              |     1
   % set x                    |
   1                          |
   % winsend send TCLSH.EXE set y 2
                              |     % after 2000 {set zx 1} ; vwait zx
   2                          |     % set y
                              |     2
                              |     % exit
   % winsend interps          |
   tkcon.tcl                  |

As you can see from the above session - we require an event loop to be running to handle the incoming send. Technically, this is because we are using an Apartment threaded object and COM apartments serialize access to object by using the Windows message queue. A future version could side-step this by creating a free-threaded object but we are trying to implement Tk's send here.

An interesting side-effect is that we can access the running tcl interpreter from any COM based language. Here is an example of a VB script file you can run using 'cscript test.vbs' under windows. It will also work from MS Word's macro editor etc. You need to start up an interpreter and load the winsend package (for instance - using tkcon):

  Set interp = GetObject("\\.\TclInterp\tkcon.tcl")
  interp.Send "puts {Hello from VB Script}"
  WScript.Echo interp.Send("info tcl")

You should see the message printed in your tkcon window and see your Tcl version printed in your DOS box.

Documentation at http://tclsoap.sourceforge.net/winsend.html and the package can be obtained at http://prdownloads.sourceforge.net/tclsoap/winsend-0.4.zip

PT


Category Package