Tcl/Tk on Windows Frequently-Asked Questions

Skip to first unread message

Jul 17, 2001, 6:39:39 AM7/17/01
Archive-name: tcl-faq/tk/windows
Posting-Frequency: monthly
Last-modified: 1999/07/13

Newsgroups: comp.lang.tcl, comp.answers, news.answers
Followup-To: poster

Archive-name: tcl-faq/tk/windows
Posting-Frequency: monthly
Last-modified: 1999/07/13

Tcl/Tk on Windows Frequently-Asked Questions

Tcl is a scripting language that runs on Windows, UNIX and
Macintosh platforms. Tk is a standard add-on to Tcl that provides
commands to quickly and easily create user interfaces. Even though
Tcl was originally created on UNIX, your Tcl scripts should run the
same on all supported platforms, except for a few differences. This
document describes those differences on Windows.

This list of frequently-asked questions, also called a FAQ, covers
problems with the Tcl/Tk programming on the Windows platform.
Please send any additions or corrections to Eric Foster-Johnson
(the email address is at the bottom). This FAQ is located on the
Internet at the following URL:

Getting Started

Tcl/Tk runs on the following versions of Windows.

Windows 3.1
Requires Win32s 1.30; no support starting with version

Windows 95

Windows 98
Some problems reported in comp.lang.tcl Internet newsgroup.

Windows NT

Windows CE
A port appears to be in progress; please keep me informed.
I will gladly beta-test a CE version on my SH3 (LG Phenom
Ultra) system.

First, get the binary release of Tcl/Tk for Windows. The latest
release is Tcl/Tk 8.1.1, tcl811.exe. Each binary release comes as a
self-extracting archive. Run the program to install Tcl.

Note: The default installation location is C:\Program Files\Tcl.
Directory names with spaces can cause some problems with Tcl,
so I recommend installing into the C:\Tcl directory.

Once you have installed Tcl, you can double-click on any .tcl file
in the Windows Explorer to run the Tcl script.

Creating Scripts

Tcl script files are really plain text files and should end with a
.tcl extension. You can use any editor that can create text files
(including Microsoft Word) to edit your Tcl scripts. Two editors
recommended on the Internet include HomeSite (really intended for
editing Web HTML files) located at and the
Programmer's File Editor, located at The WordPad editor, which
comes with Windows, has lots of problems, especially since it likes
to append a .txt extension to all text files it creates (and you
want a .tcl extension for Windows Tcl scripts).

Learning Tcl

The Tcl language is described in a number of books, including:

Tcl and the Tk Toolkit by John Ousterhout, Addison-Wesley,

Practical Programming with Tcl and Tk by Brent Welch,
Prentice Hall, 1997.

Graphical Applications with Tcl and Tk Second Edition by
Eric Foster-Johnson, M&T Books, 1997, a book by yours truly
that covers cross-platform development with Tcl and Tk on
Windows and UNIX.

Effective Tcl/Tk Programming by Mark Harrison and Michael
McLennan, Addison-Wesley, 1997.

I maintain a number of Web pages on Tcl that can also help.


Questions answered here include:

How to get Tcl/Tk For Windows
A-1: Binary release of Tcl/Tk.
A-2: How to Run Scripts from Windows

Installing/Can't Run At All
I-1: Don't upgrade over a previous version

Differences From Unix
D-1: \ Won't Work!
D-2: How to create a valid font name on Windows
D-3: Cut, copy and paste in the Tcl Console window
D-4: Using the Windows Clipboard
D-5: send is not implemented on Windows
D-6: Start-up Files tclsh.rc and wishrc.tcl
D-7: Accessing PC serial ports from Tcl
D-8: Using UNC file names
D-9: Getting list of mounted drives
D-10: Accessing the Windows Registry
D-11: Using Dynamic data Exchange (DDE)
D-12: winfo interps and send fails on Windows
D-13: Installing Tcl/Tk Applications on Windows
D-14: Making executable scripts on NT

Windows-Specific Bugs and Problems
B-1: Puts bugs.
B-2: fileevent only supports sockets under Windows until
B-3: You need at least 256 colors and may have problems
with more than 256
B-4: Problems with clock command on Windows
B-5: wm iconbitmap doesn't work on Windows
B-6: If you use a pipe (|) in open, until the child process
has terminated no events will be processed.
B-7: The rightmost mouse button is Button-3.
B-8: Tk on Windows supports cursors
B-9: Sockets are not available on the system error
B-10: toplevel -container does not work
B-11: exec: couldn't create error file for command: Error 0

Old Bugs
O-1: Wish uses a lot of system resources and doesn't free
O-2: Once exec fails, the next exec generates a fatal

Compiling and Writing C and C++ Extensions
C-1: Getting the source code
C-2: Tcl no longer compiled with Borland C++
C-3: Tcl uses long file names
C-4: Where are the .lib files?
C-5: Creating Dynamic Extensions on Windows
C-6: C++ and DLLs
C-7: Compiling with EGCS/Ming32
C-8: Allocate memory with Tcl_Alloc
C-9: Tcl and Microsoft Foundation Classes

E-1: Expect
E-2: Tix works on Windows.
E-4: Network, Registry and ODBC Extensions
E-5: Itcl
E-6: BLT Win32 Patches
E-7: VerTcl/TkCon Provides a Useful Console On Windows
E-8: OCX Extensions for Tcl
E-9: TkTable
E-10: MDI (Muliple Document Interface)
E-11: Windows shortcuts extension
E-12: TclX
E-13: Togl (Tk OpenGL)
E-14: cc::Mail
E-15: Tabbed dialogs, Combobox, etc.
E-16: DLL-Caller Extension
E-17: WinExec, Print, and Other Extensions
E-18: Winico Extension
E-19: Img Extension
E-19: ActiveTcl Extension

Windows 3.1 Issues
W3-1: Windows 3.1 Requires Win32s
W3-2: How to execute tclsh76.exe from Windows 3.1
W3-3: Strange behaviour of exec under Win 3.1
W3-4: Windows 3 doesn't support help contents file
W3-5: Wish generates a UAE error at startup
W3-6: Increasing environment space in DOS.


How to get Tcl/Tk For Windows

A-1: Binary release of Tcl/Tk for Windows

Tcl/Tk 8.1.1 is available at

This is a self-extracting archive.

A-2: How to Run Scripts from Windows

How do I run a script?

There are three approaches to starting scripts in Tcl: source,
shortcuts, and file associations.

The most obvious way is to launch the Wish application and use
"source". This is the best way to debug scripts.

The second alternative is to create a Program Manager icon (Windows
3.x or NT 3.x) or a shortcut (Windows 95). The binary release uses
this technique for the widget tour icon. The command line for the
icon should be something like:

c:\tcl\bin\wish81.exe c:\myscript.tcl

The third way to launch a Tcl script is to create a file type
association for the extension ".tcl" (or ".tk"). Using the File
Manager (or My Computer in Windows 95), create a new file type for
.tcl, and add an "open" action. The command for the action should
be something like:

"c:\Program Files\tcl\bin\wish81.exe" "%1"

Once you have set up the association, you will be able to double
click on script files in File Manager to launch the app.

Note that if either the location of wish or the location of the
script contains spaces in any of the file names, you must enclose
the name in quotes. For example:

"c:\Program Files\tcl\bin\wish81.exe" "c:\Program

-Scott Stanton

You may also want to add an Edit action for Tcl files. For this,
you need to pick an editor that won't place extra carriage returns
on the end of lines. (Windows uses a carriage return/line feed
combination to end each line of text, while Unix only uses a line

In the Windows 95 Explorer, pick the Options choice from the View
menu. Under the File Types tab, find your Tcl file type and Edit
it. Under Actions, click New and name your new Action Edit. Choose
your editor and accept all your changes.

You should now be able to easily bring up an editor with a
right-click on the file and the Edit popup option.

-Hume Smith


Installing/Can't Run At All

I-1: Don't upgrade over a previous version

It seems there is a bug in the Windows binary installer. If you are
installing over the top of a prior version of Tcl, it is not
correctly handling the versioning for the libraries. You will end
up with a mixture of old and new files. The symptoms vary, but if
you are seeing problems with the console or other stdio related
features, the installer could very well be the culprit.

The solution is to completely remove the old/broken installation
and reinstall from the release file. This should give you a
consistent set of files.

Thanks to Gerald Lester for helping to identify this problem.

-Scott Stanton


Differences From Unix

D-1: \ Won't Work!

Remember that \ is a special character in Tcl.

This is a problem because Windows uses a backslash for separating
directories, while Unix uses a forward slash.

So, in Tcl and in the Tcl shell, wish, you need to enter
directories and paths with either two backslashes, e.g., \\, or
with the Unix-style forward slash, e.g., /.

For example, don't use:


Use either:




You can use the file join command to put file and directory names
together using the native format.

D-2: How to create a valid font name on Windows.

You can either use X Window font names, in X Logical Font
Description (XLFD) format, or a special Windows-specific format.
With Tk 8.0 or higher, you should use the font command, which
allows you to create cross-platform font definitions. This is much
better than the older methods!

If you are working with versions of Tk prior to 8.0, you need to
set up XLFD font names or Windows-specific names, discussed below.

1. XLFD format font names

Windows Tk will accept X font names, but you must supply all the
parts (you can use a * for a wild-card, though, see below). You can
also use a number of XLFD elements, such as "bold", etc. to control
the fonts.

For example, the following all are valid font names on Tk in

button .b1 -text "Arial" \
-font "-*-arial-bold-r-normal--*-*-*-*-*-*"
button .b2 -text "Courier" \
-font "-*-courier-medium-r-normal--*-*-*-*-*-*"
button .b3 -text "Symbol" \
-font "-*-Symbol-medium-i-normal--*-240-*-*-*-*"
pack .b1 .b2 .b3

To get the list of valid Windows font names, look in an application
like Microsoft Word (or WordPad, which comes with Windows 95) and
check the font list. Most True Type ("TT") fonts should be scalable
to a number of sizes.

You can find out more in depth information about XLFD naming
formats at

-Eric Foster-Johnson

2. Windows-specific font names

In addition to the X style font names, Tk starting with version 4.2
accepts a special tuple format consisting of a 3 element list of
the form:

{name size stylelist}

You can use any font name that Windows understands for the first
element. The size is in points, and the style is a list of zero or
more items from the set of supported styles: normal, bold, medium,
heavy, thin, extralight, light, semibold, extrabold, italic,
oblique, underline, strikeout. Many of these styles won't do
anything for a given font. For example, to get a 20 point TrueType
Times Roman font with bold and italic style, you would say "{Times
Roman New} 20 {bold italic}".

Note that the 3 part font specifier is just a place holder for font
objects. Eventually we will support font objects that take various
configuration options and return a handle that can be used anywhere
a font string is used now.

-Scott Stanton

D-3: Cut, Copy and Paste in the Tcl Console Window

The Tcl Console window sets up bindings that are supposed to follow
the Windows (and IBM Common User Access, or CUA) standard of

* Ctrl-x: cut

* Ctrl-c: copy

* Ctrl-v: paste

In Tcl 8.0, the Ctrl-V does not work for paste. (The Paste menu
choice does work, though.) In Tcl 8.1, Ctrl-V works fine.

For older versions of Tcl/Tk, prior to 8.0, the Tcl Console window
(by default) provides the following bindings:

* Ctrl-x: deletes selected text

* Ctrl-w: cut

* Alt-w: copy

* Ctrl-y: paste

-Eric Foster-Johnson

D-4: Using the Windows Clipboard

Associated with the Cut, Copy and Paste functions, the selection
functions do work between Windows apps and Tcl/Tk scripts.

To see this, try the following: select some text in Microsoft Word,
Write or any other Windows app. Copy the data to the clipboard
(inside the app). Then, enter the following at your wish prompt:

set clip [selection get -selection CLIPBOARD ]

The variable clip should now hold the data from the clipboard.

The parts that may be troublesome are that:

* UNIX apps tend to use an active copy and paste with the PRIMARY

* Windows apps tend to use a passive copy and paste, placing the
data in the clipboard as an intermediary stopping point between
the applications.

* Motif applications on Unix do use the CLIPBOARD selection.
Decoding the Motif clipboard is a left as an exercise for the

* The X selection mechanism handles a lot more than text, which
introduces some interesting complexity.

All in all, Tk does pretty good with handling selections on
multiple operating systems.

-Eric Foster-Johnson

D-5: send is not implemented on Windows

Furthermore, it is unlikely send will be ported soon, because send
uses the X server for communication. Use the dde command instead.

D-6: Start-up Files tclsh.rc and wishrc.tcl

Tcl looks for ~/tclsh.rc, and wish looks for ~/wishrc.tcl. The
tclsh.rc name is pretty inconsistent, and should probably be
tclshrc.tcl. We don't use the .tclshrc form because it doesn't work
on FAT filesystems. -Scott Stanton

D-7: Accessing PC serial ports from Tcl

Open the serial port using "set comdesc [open COM1: RDWR]", then
use "read|write|gets|puts $comdesc" to access it. Don't forget to
close it ("close $comdesc") when you're done.

-Michael Schumacher

D-8: Using UNC file names

If you have machines networked, you can test for file existence
generally with:

file exists //NetworkName/c/

However, I'm do not believe there is any way in Tcl to tell what
mapped drives are mapped to.

-Jeffrey Hobbs

D-9: Getting List of Mounted Drives

Starting with Tcl 8.0 you can use the file volume command to return
a list of mounted volumnes, for example:

file volume
A:/ C:/ D:/ E:/ G:/ H:/ I:/ Q:/ T:/ V:/ X:/

D-10: Accessing the Windows Registry

Starting with Tcl 8.0 you can use the registry package on Windows
to access the registry.

This package is only available on Windows.

Note that the registry uses backslashes as separators and that Tcl
treats a backslash as a special character. For example:

package require registry
registry keys "HKEY_CLASSES_ROOT\\TclScript\\shell"
edit open

D-11: Using Dynamic data Exchange (DDE)

See for more on
the dde package included in Tcl 8.1.

From a posting by Bill Schongar, at, you can control
Microsoft Word from the dde command. First. be sure Word is
running, then try a command like the following to insert text into
the current document:

package require dde

dde execute -async Winword System {[Insert "Text from Tcl."]}

To quit Word, or close a document, use the following commands as a

dde execute Winword System {[FileExit 2]}

dde execute Winword System {[FileClose 2]}

In these examples, 2 = close without saving, 1 = save first, 0 =

For documentation on accessing Word, see the "wrdbasic.hlp" file,
which you can choose to install when you install Word.

D-12: winfo interps and send fails on Windows

Unfortunately, neither "winfo interp", nor "send" are implemented
in any of the Tk for Windows releases. Hopefully this will be
available in the next release.

-Scott Stanton

D-13: Installing Tcl/Tk Applications on Windows

Steve Cassidy is working on a method for installing Tcl/Tk
applications with libraries and everything else. Here's his

I've posted here a couple of times saying that I'm working on an
installation method for tcl/tk apps under windows which bundles the
tcl/tk binaries and libraries with my own. Well I've just put
together an example of this which folks might want to look at and

You can find a self extracting, self installing exe file at:

This contains the tcl/tk 8.0.3 distribution compiled by myself with
Borland v5.0 plus my extensions and some of my own standalone
executables. The self-installer runs a wish script which copies the
files into the appropriate place (after prompting), adds a program
group to the start menu (via the dde extension), and puts the
appropriate things in the registry (for tcl/tk and Emu). It also
builds an uninstall script which removes everything except the
start menu items (I can't figure out where they are).

It should be possible to install this package beside an existing
tcl8.0 installation, I've modified the core to look for a different
registry key (../scriptics/tcl/emu, rather than

****TAKE CARE!!! I can take no responsibility for your machine, I
have been as careful as I know how to be but this code has only
been tested on one NT4 machine so far.******

The application is a speech database system, tcl/tk is used as a
scripting language and to build gui elements like a labeller which
can display speech signals and spectrograms etc. If you want to
actually see how this works you will need some speech data and a
database template file see for

If you do install this, you should be able to run the Emu Labeller
and get something other than an error message (without a database
template you can't do anything). You should also be able to run
wish80 and do any tcl stuff you desire.

I'd be interested in any reports of success, failure or just
comments on this methodology. If this turns out to be of general
interest I will document and package up the scripts needed to
achieve the installation.
-Steve Cassidy

D-14: Making executable scripts on NT
You can make a Tcl script into a direct executable following the
guidelines on the Web at:


Windows-Specific Bugs and Problems

B-1: Puts bugs

The following Tcl procedure may fail on Windows NT, depending on
the amount of data written to the file:

proc testPuts { fileName output times } {
set fileID [ open $fileName w ]
for { set i 0 } { $i < $times } { incr i } {
puts $fileID $output
close $fileID

When it fails, there are only a couple of characters in the output
file (basically garbage). The Tcl error reports back:

error writing "fileX": No error

For example, if I call:

testPuts {C:/TestFile} {HI THERE} 455

it works perfectly well. However, if I call:

testPuts {C:/TestFile} {HI THERE} 456

it fails.

You can work around this bug by flushing the file descriptor after
each puts call, like the following:

proc testPuts { fileName output times } {
set fileID [ open $fileName w ]
for { set i 0 } { $i < $times } { incr i } {
puts $fileID $output
flush $fileID
close $fileID

The big question is whether this is a bug in Tcl or Windows NT
3.51. Has anyone seen this before or have any related information?
If it is a bug in Windows NT, will Tcl7.5b2 handle this?

-Brian L. Rubow

B-2: fileevent only supports sockets under Windows until 8.1

Fileevents are supported on Win32 platforms for sockets only.

With Tcl8.1, you can now call fileevent on pipes on Windows.

In the expect for NT distribution the fileevent
problem on windows is solved for tcl8.0p2 too.

-Leo Schubert

B-3: You need at least 256 colors and may have problems with more
than 256

A number of people have reported that wish simply won't work unless
you set your screen resolution to have at least 256 colors and
preferably, 1024x768 pixel resolution.

If you have more than 256 colors, images may not display correctly
under Tk 4.2.

B-4: Problems with clock command on Windows

Beware of clock format commands across operating systems

Tcl's clock format command eventually passes it's format string to
strftime(). strftime() may have different implementations depending
on the underlying operating system.

For example, Windows NT 3.51 doesn't implement the %D, %e, and %h
directives. This can some interesting side effects.

The bug report: If you do supply one of these unknown directives
(and nothing else), Tcl can go into a loop. The FormatClock routine
keeps calling strftime() because it mistakenly assumes that a 0
return must mean that the target buffer is too small. Indeed, if
you just pass it "%e", the strftime() function gets annoyed at it
as a directive and erroneously returns 0. Oddly enough adding a bit
of whitespace to the format command gets rid of the loop.

This may be an NT oddity only, I don't think you can know for sure
that it won't happen elsewhere.

-Dave Griffin

B-5: wm iconbitmap doesn't work on Windows

The wm iconbitmap command does not work on Windows. if you execute
the following command, you'll still see Tcl's icon for your

wm iconbitmap . filename

To change this, you need to substitute your own .ico file and
recompile the relevant parts of the Tk source code.

-Eric Foster-Johnson

B-6: If you use a pipe (|) in open, until the child process has
terminated no events will be processed

If you start a process in a pipe, e.g., 'open "| ...."' until the
child process has terminated no events will be processed.

-John Robert LoVerso

B-7: The rightmost mouse button is Button-3

Even with a two-button mouse, the rigthmost mouse button is
identified in Tk as Button-3.

This really isn't bad, especially if you coded your pop-up menus to
appear on Button-3 events, following the style of most Motif
programs. Your scripts will continue to work on Windows.

-Eric Foster-Johnson

B-8: Tk on Windows supports cursors

The -cursor option should work on Windows now with all the built-in
X Window cursors.

B-9: Sockets are not available on the system error

If you get an error like the above, chances are you have not
installed the winsock.dll dynamic-link library that adds networking
socket functionality to Windows.

B-10: toplevel -container does not work

The -container option is not fully implemented on Windows at
present. The only functionally complete implementation is on X

You can use the '-use' option as long as the supplied window ID
identifies a window that is not managed by Tk. This is known to
work on both Unix and Windows. The Mac implementation is not, as
far as I know, able to handle this in the general case; we did
something special (a hack :) for the Tcl plugin on the Mac.

I cannot say when things will get better on this front. It's on our
todo list and will percolate upwards according to demand etc etc..

-Jacob Levy

B-11: exec: couldn't create error file for command: Error 0

If exec returns an error message of "couldn't create error file for
command: Error 0", the following may help:

This problem exists under Unix and Windows NT. I have conclusive
proof that under Unix it was being caused by the temporary
directory not being world writable, which explains why superusers
were able to "exec" something but not a regular user. The "gotcha!"
is that /tmp is not necessarily the temporary directory that is
used, so people were not seeing an obvious problem. Tcl uses the
tmpnam() system call, which on many systems actually uses /var/tmp,
and on some systems that directory was not world writable. I would
like to call this a problem with one's site administration.

Here's a simple program to determine your temporary directory:

char name[100];

which prints out the full pathname for a potential new temporary
file. If the specified directory is not world writable, you can't
create temp files.

Now, the question turns to Windows. This I have not yet resolved.
Under NT, which has users and directory permissions, it may be the
same problem as under Unix. However, since this problem is also
occurring under Windows 3.1 it may be another problem or
combination of the two. I will post results as soon as possible.

-Colin Stevens


Old Bugs

O-1: Wish uses a lot of system resources and doesn't free them.

Wish does not release the system resources it uses even when it
exits normally. Run through the widget demo, exit and look at the
system resources count. You may find it dropped by 17%. During the
widget demo, monitoring system resources found that wish does not
seem to release system resources when it destroys widgets. During a
wish session free resources just keep declining. Given this
situation, large wish applications may slow down or crash.

-Charles A. Shartsis

O-2: Once exec fails, the next exec generates a fatal error.

Tcl7.5a1/Tk4.1a1 bugs with exec on Windows.

Once an exec command fails the next exec command results in a fatal
error (when typing exec commands into the Console window). For

tcl> exec xyzzy
Couldn't read output file "TMP37.$$$" for command: no such file or
tcl> exec dir

and you will get a popup window about the fatal error...

Other exec bugs on Windows:

I'm using the recent b2 release with Windows 95 with tclsh75.

Exec is not redirecting output properly. There seems to be a race

When I try 'exec co -p foo.c > bar.c', co should write to stdout
and tclsh75 should redirect the output to a new file.

Instead, co -p writes to stdout and it appears on the console
window. If I attempt to grab the output by doing:

set result [exec co -p foo.c > bar.c ]

result is set to "" after the command, even though co writes out
the file to stdout.

Now it gets interesting: If I trace through Win32Pipeline() and
stop at the CreateProcess() call, and then step through it closing
the files, the whole thing works the way it should - that is, co
writes to stdout, which goes into a file. If after it stops at
CreateProcess() I hit the continue, everything breaks again. So it
seems that tclsh needs to create the rpocess and close down the
files before letting the child run. Very odd.

-Josh Putnam

- When you exec a command the screen blanks out (system -> DOS?)
and then redraws as the command ends. Can this be stopped?

- There is a resource leak somewhere in the exec command. If you do
"exec dir" several times you will find that the Free Memory and
Free System Resources (as in Program manager/Help/About) decrease
each time.

-Gordon Lack

Calling exec brings on blank-screen mode

In article <>, Shicheng Tian
<> wrote:

On my PC, from Windows, I run a tcl script file with the following
one line code:

exec del "c:/rubish.tcl"

The file 'rubish.tcl' DOES get deleted, but the trouble is:

the PC goes back to the DOS environment (i.e. a black screen!),
then it comes back to Windows again.

My enquiry is: is it possible to run the 'exec' command shown as
above WITHOUT showing the DOS black screen?

You can change this behavior by modifying the .PIF file for MS-DOS
so that it does not use full-screen mode.

-Scott Stanton

Another way to call exec

It wasn't obvious to me either how to get native DOS window
commands to work and it sometimes hung on me as well. I recently
got it working, however...

exec cmd.exe >&@stdout <@stdin /c dir

will do the directory command for the current directory. Check out
the Windows help for the switches available under cmd.exe. "/c"
tells it to execute the command and then exit. "/k" tells it to
execute the command and keep the DOS command interpreter active.
(Note that cmd.exe is the name of the MS-DOS interpreter on Windows

-Robert Philpott

Only Call exec on 32-bit Applications

Tcl 7.6 and Tk 4.2 seem to have solved the following problem.
(Thanks to Colin Stevens.)

Tcl/TK for Win32 is really rotten at doing an exec on DOS mode
programs. This includes any of the DOS-like commands of the Win95
shell! If you use exec with any of the DOS mode commands, the
command might execute but control will never be returned to the
WISH shell.

However, 32 bit programs work just fine with WISH. To see what I
mean, try the following command from the WISH console:

exec notepad

This command will run the Windows notepad editor and return control
to WISH after the notepad program is exited. If you want to run
notepad and return control immediately to WISH just use:

exec notepad &

This behavior is identical to the UNIX versions of Tcl/TK.

So, the moral of the story is:

Only "exec" 32 bit programs with the Win32 version of Tcl/TK.

-Dennis R. LaBelle


Compiling and Writing C and C++ Extensions

C-1: Getting the source code

The Tcl releases officially support UNIX, Windows and Macintosh
platforms. The source code comes with a win/ directory with Windows
code. You can get the source code release on the Internet via FTP
from, in the directory /pub/tcl.

For Windows users, you'll likely want the source code compressed in
ZIP format, rather than GNU gzip. Pick up the files ending in .zip.

The source code was compiled with Microsoft Visual C++ 5.0. For
more on compiling the sources, see

With MS VC++ 5.0, the default installation places the compiler in
\Program Files\DevStudio\VC. Because of the space in the name
Program Files the -I (include file) option in the makefiles may
fail because spaces are used to separate command-line parameters.

You can use the short (DOS) directory name in place of the Program
Files, e.g. -Ic:\progra~1\devstudio\vc\include in place of
c:\Program Files\DevStudio\VC\include. You can also place the
commands in the files in quotes, e.g.:

cc32 = "$(TOOLS32)\bin\cl.exe"
link32 = "$(TOOLS32)\bin\link.exe"
rc32 = "$(IDE32)\bin\rc.exe"
include32 = -I"$(TOOLS32)\include"

-Eric Foster-Johnson

C-2: Tcl no longer compiled with Borland C++

Until about Tcl 8.0.3, Tcl was compiled with Borland's C++
compiler. With 8.0.3 and beyond, the Scriptics team switched to
Microsoft's C++ compiler, Visual C++.

Michael I Schwartz has a good note at on how to continue
using Borland's C++ compiler with DLLs compiled by Microsoft's

-Eric Foster-Johnson

C-3: Tcl uses long file names

Both Tcl and Tk use long file names. You'll need Windows 95 or
Windows NT (with an NTFS file system) for the sources.

You may also need a modern ZIP program to extract the archive and
maintain its long file names. Older versions of pkzip, for example,
only understand the old DOS eight character (with up to three
characters for an extension) file names. I use WinZip, a shareware
archiver program for Windows.

-Eric Foster-Johnson

C-4: Where are the .lib files?

When you install Tcl, you can specify that you want the library
files installed. If you do so, you'll see the libraries in the lib
subdirectory wherever you installed Tcl. For example, C:\Program

C-5: Creating Dynamic Extensions on Windows

See for more on
building extensions for Windows.

C-6: C++ and DLLs

If you write your Tcl extensions in C++, you'll likely need to use
the extern "C" { }; statement in C++ to use your functions in Tcl.
This is due to the user of "name mangling" in most C++ compilers.

-Eric Foster-Johnson

This especially true for your exported Init routine for the

#ifdef __cplusplus
extern "C"
EXTERN int Foo_Init (Tcl_Interp *interp) {
return TCL_OK;

Where "Foo" is the DLL's name. If your extension is called
calcBIG.dll, use "Calcbig_Init" for the function's name. Notice
that the first letter is always capitalized and all following
characters are lower case.

-David Gravereaux

C-7: Compiling with EGCS/Ming32

To get Tcl/Tk to compile on Win32 systems with the EGCS compiler,
you need patches available at

See for more
on Ming32, EGCS, and other free compilers for Win32 systems.

C-8: Allocate memory with Tcl_Alloc

If you allocate memory from within a C or C++ program and pass that
memory on the the Tcl DLLs, you must allocate that memory with

If you allocate memory via some other means, pass that memory to
Tcl and later get a crash, you were warned.

C-9: Tcl and Microsoft Foundation Classes

CTkView is a C++ class which can be used in MFC SDI or MDI
applications. An instance of CTkView hosts an embedded Tk toplevel
widget and performs some management chores for the widget so that
it can size, update and react correctly to Windows events.

-David Shepherd

For more information, see



E-1: Expect

Expect works on Windows NT. You can get it from:

E-2: Tix works on Windows

The Tix extension has been ported to windows.


OdbcTcl 0.2 for Win32 provides a Tcl extension to call ODBC 2.0
functions from Tcl.

You can get it from in

A common problem appears regarding the DSN value. A cample connect
command is:

odbc_connect sql "DSN=mydb;UID=foo;PWD=bar"

-Jose L Porcayo

An ODBC extension to Tcl is available at

E-4: Network, Registry and ODBC Extensions

NT, ODBC, network, and registry extensions available for the
Windows version of TCL (7.6) are available at:

-Christopher M Sedore (

E-5: Itcl

Itcl 2.2 and higher works on Windows.

E-6: BLT Win32 Patches

Patches for the BLT 2.1 extension for Win32 are available from:

Status: Tiled widgets problematic, bgexec/busy not working,
drag&drop ok with dde.

In addition, you can get a Tcl Win32 Mem Debug patch, to allow for
debugging output on memory allocations to get sent to the console.
This is available from:

E-7: VerTcl/TkCon Provides a Useful Console On Windows

VerTcl (also called TkCon) provides an enhanced console window that
proves very useful on systems that don't provide built-in consoles,
such as Windows and MacOS.

You can get more information on VerTcl/TkCon, and the code, too,

E-8: OCX Extensions for Tcl

There are a number of OCX extensions for Tcl, including:
AxTcl (formerly TclOCX) is an ActiveX DLL extension. This
enables Tcl to dynamically load command extensions from
ActiveX DLL's.
An ActiveX extension for Tcl. This extension allows you to
use existing OCX or ActiveX controls in a widget-like way.

An experimental ActiveX control.

E-9: TkTable

tkTable 2.3, an editable 2D table/matrix widget. Supports Unix
Tcl/Tk variants and Windows, requires Tcl/Tk 8+.

E-10: MDI (Muliple Document Interface)

There is a very nice Tcl-only package called mdw-lib (Multi
Document Windows) written by Thomas Schwarze
( that does that kinda stuff. You
can find it at:

-Frederic Bonnet

E-11: Windows shortcuts extension

This is an early release of a shortcut manipulation extension for
tcl 7.6/tk 4.2. It allows you to create, modify, and get
information from a NT 4.0 or Windows 95 shortcut.

Docs are available at

Download from:

-Chris Sedore

E-12: TclX

Extended Tcl is a set of Tcl extensions and a shell that are
oriented towards Unix system programming tasks and large
application development. TclX 7.6.0 is compatible with Tcl7.6 and
Tk 4.2 releases.

This release includes incomplete support for Windows 95/NT as well
as a binary release for Windows 95/NT.

Full source for Unix and Windows:

Windows 95/NT binary release, tar and gzip format:

Windows 95/NT binary release, zip format:

If you have any questions or problem, please remember to contact directly.

E-13: Togl (Tk OpenGL)

See for
information on Togl for NT, for more on Togl.

E-14: cc:Mail

Electric Memo Ltd. has a shareware Tcl add-on called Xccm that
allows access to cc:Mail via the VIM32 dlls.

E-15: Tabbed dialogs, Combobox, etc.

While this isn't an extension, Jeff Hobbs provides a number of
widgets written in Tcl, including a tabbed dialog and combobox.

E-16: DLL-Caller Extension

Robin Becker's dll package, at, allows your Tcl
scripts to call functions in Win32 DLLs (Dynamic Link Libraries).

E-17: WinExec, Print, and Other Extensions

Michael Schwartz offers a number of Windows extensions that include
winexec to launch 16-bit Windows applications and print, which, as
you'd expect, allows you to print from Tcl scripts.

E-18: Winico Extension

The Winico extension introduces one new command called "winico" to
load .ico files from the harddisk or icon resources from the system
and to set the taskbar-icon (when hitting Alt-Tab) and the icon in
the caption of a Tk-toplevel. It can also display icons in the
taskbar status area. Winico is available at Send bug reports to

-Leo Schubert

E-19: Img Image Extension

The Img extension adds support for more image types to Tcl/Tk.
available for Windows and UNIX from:

E-20: ActiveTcl BGI Tcl Windows Extension

A new version of ActiveTcl (a ActiveX wrapper for tcl8) is
available free of charge (for non-commercial use) from BGI

Two tcl loadable DLLs are also provided :

* tclwin is an interface for win32 to creates MDI interface and
non-modal dialog boxes.

* Two sample scripts demonstrate the use of tclwin and tclodbc :

* Tclwined.tcl is a stand-alone dialog box editor and tcl

* Odbcwiz is a general purpose ODBC query tool.

Everything can work stand-alone or combined. A help file is
provided in the package.

Works with : tcl8 for win32 (NT,95,98).

- N. Frankinet


Windows 3.1 Issues

W-1: Windows 3.1

If you run Windows 3.1, you will need to install the Win32s
subsystem. You may have already done that. Check that you have the
Win32s DLL (dynamic-link library) at version 1.30. If not, you can
get a self-extracting archive, w32s130.exe, from:

Extract this file in an empty directory.

If you use Windows NT or 95, you won't need the Win32s subsystem.

Note: If you're using an older version of Win32s, you must
upgrade to version 1.30.

Note: Tcl/Tk support for Windows 3.1 is gone with Tcl 8.0.3. To
run under Windows 3.1, you need to use an older version of
Tcl/Tk, such as 7.6p2 or 8.0p2. You really need to upgrade to a
newer version of Windows.

-Eric Foster-Johnson

W3-2: How to execute tclsh76.exe from Windows 3.1

You can run tclsh76.exe under Windows 3.1, but not from a DOS
shell. You can invoke tclsh76.exe by making a program manager icon
for the command line that you want to execute. Since tclsh76.exe is
not a DOS application, you can not invoke it from the shell.

-Scott Stanton

W3-3: Strange behaviour of exec under Win 3.1

Unfortunately the support for exec under Win32s is very limited.
Most of this is because of Win32s. There are definitely some
improvements that could be made (e.g. letting you start Windows
apps), but it is never going to be as good as the Windows 95 or NT
versions. Basically Windows 3.1 doesn't have a very complete
process model, and most of what you see in the DOS window is done
using non-Windows APIs. I could probably get Tcl to do the same
things, but it's going to require a lot of very Windows 3.1
specific coding to get it to work. There are a number of other
things that are higher priority, so it probably won't happen for a
while. I would encourage anyone who really wants this feature to
work on it and send me patches.

-Scott Stanton

W3-4: Windows 3 doesn't support help contents file

The problem is that Win3.1/3.11 don't support the contents file. I
think what is needed is an additional help page that lists the
contents. This is redundant under Windows 95 and NT, but necessary
for 3.1/3.11.

For now, however, you should be able to use the keyword search
facility to get to any of the man pages.

-Scott Stanton

W3-5: Wish generates a UAE error (Unhandled Win32s Exception) at

If you get a UAE error when starting wish on Windows 3.1 (this
problem does not appear on Windows NT), here's what you can do.

1. Add the following lines to your autoexec.bat file:

set tcl_library=/tcl/lib/tcl8.0
set tk_library=/tcl/lib/tk8.0

Note that these paths refer to the standard installation of wish,
e.g., C:\tcl. If you installed in a non-standard location, you'll
need to modify this. Also note the forward (/), not backward (\)
slashes for directory separators.

2. You can also type in the values at a shell (i.e., DOS) command
line, but wish is a Windows program, so this must be placed into
the environment for Windows. When I typed these commands in at the
DOS level, I received an error that I had run out of environment
space. This may also be a problem for you. DOS 5 only allows a
small amount of space for environment variables. If this is the
case, you'll need to remove other environment settings (I pared
down my PATH, which came from the manufacturer with extraneous

3. You must reboot, since the autoexec.bat is only read at

-Eric Foster-Johnson

W3-6: Increasing environment space in DOS.

If you type in the tcl_library and tk_library environment variables
and get an out of space error, you can increase the amount of
memory allocated to the DOS environment through the COMMAND.COM
command line options. For example, add the following line to your

shell=c:\ /e:1024 /p

This sets the environment space to 1K. Note that (on my system, at
least) the /c autoexec command is needed to make DOS run the
autoexec.bat file during booting.

-Alex Hubbard


Thanks To:
Frederic Bonnet
John Buckman
Steve Cassidy
Gordon Chaffee
Joe English
N. Frankinet
David Gravereaux
Dave Griffin
Jon Herlocker
Alex Hubbard
Dennis R. LaBelle
Gordon Lack
Ioi Lam
Jacob Levy
Don Libes
John Robert LoVerso
Cristian Mata
Ola Noss
Robert Philpott
Jose L Porcayo
Josh Putnam
Brian L. Rubow
Bill Schongar
Leo Schubert
Michael Schwartz
Christopher M Sedore
Charles A. Shartsis
David Shepherd
Hume Smith
Scott Stanton
Colin Stevens
Larry Virden
John Waterson

Compiled by Eric Foster-Johnson, author of Graphical Applications
with Tcl and Tk. Please send updates to

DISCLAIMER. This article is provided as is without any express or
implied warranties. While every effort has been taken to ensure the
accuracy of the information contained in this article, the
maintainer assumes no responsibility for errors or omissions, or
for damages resulting from the use of the information contained

Eric Foster-Johnson

Reply all
Reply to author
0 new messages