winsend

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.6                        |     0.6
% 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 http://tclsoap.sourceforge.net/winsend.html and the package can be obtained at http://prdownloads.sourceforge.net/tclsoap/ in the file winsend-X.X.zip

PT

LES on 26 Sep 2005: I don't understand this path \\.\TclInterp\tkcon.tcl. Is that relative? Is that the path to tkcon.tcl? Is that the path to wish (TclInterp)? Is that the path to wish (TclInterp) plus "\tkcon.tcl"? Is that the path to wish (TclInterp) plus "registered app"? I can't seem to make it work in any way.


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?


PT: The source code for this has now been loaded into the tclsoap CVS respository at sourceforge. Try

cvs -d:pserver:[email protected]:/cvsroot/tclsoap login
cvs -d:pserver:[email protected]:/cvsroot/tclsoap co winsend

to obtain the tree.


09-Dec-2002: Released winsend 0.5 to fix a problem with passing error information back to the caller.

01-Mar-2003: Released winsend 0.6 which now supports the TEA2 build system. Builds with Msys + Mingw or VC++ 6.0.


MiR 2015-11-10 Tried winsend package Version 1.0 from sourceforge today under Windows 7. When sending a malformed command (winsend send CLIENTNAME erterter) it crashes with Fatal Error in WISH, TCL_ListObjAppendElement called with shared object. I'm using TCLKit 8.6.1.b to compile a starkit via SDX. Hm, is this the intended behaviour?


See also send