Version 5 of winsend

Updated 2002-04-09 21:31:26

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 (which, on UNIX, also requires the event loop to be running - DKF) 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 and the package can be obtained at in the file


DKF: Does winsend support synchronous calls? Does it support callbacks via the winsend mechanism during the execution of a synchronous call? The standard Tk [send] mechanism does (though no other events are serviced during the [send].)

PT: Currently the winsend send command is synchronous. Asynchronous sends can be done fairly easily and might be added later on. I've added nothing for callbacks though there is no reason this cannot be done. I'm not certain what the normal [send] does for callbacks. Any examples?

Category Package