Tcl/Tk on Windows Frequently-Asked Questions 
Author Message
 Tcl/Tk on Windows Frequently-Asked Questions

Archive-name: tcl-faq/tk/windows
Posting-Frequency: monthly
Last-modified: 1997/12/02

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

   Archive-name: tcl-faq/tk/windows
   Posting-Frequency: monthly
   Last-modified: 1997/12/02

   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

    http://www.*-*-*.com/ ~erc/tclwin.htm

   SunScript has a Windows Tcl/Tk Project that contains information about
   Sun's port of Tcl/Tk to the Windows platform.

   There is also a Tcl on Windows mailing list. For more information, and
   an archive of messages, see the following URL:


   Getting Started

   First, get the binary release of Tcl/Tk for Windows. The latest release
   is Tcl/Tk 8.0, tcl80p2.exe. (The p2 part stands for patch-level 2, or
   the second update to the 8.0 release.) Each binary release comes as a
   self-extracting archive. Run the program and install Tcl.

   The previous main release was win76p2.exe.

   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.

   Tcl script files are really ASCII 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 http://www.*-*-*.com/ 's File Editor,
   located at http://www.*-*-*.com/
   has lots of problems, especially since it likes to append a .txt extension
   to all text files it creates.

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

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

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

           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.


   Questions answered here include:

     How to get Tcl/Tk For Windows
           A-1: Binary release of Tcl/Tk.
           A-2: Windows 3.1 Requires Win32s

     Installing/Can't Run At All
           I-1: Don't upgrade over a previous version
           I-2: Wish generates a UAE error at startup
           I-3: Increasing environment space in DOS.

     Differences From Unix
           D-1: \ Won't Work!
           D-2: How to create a valid font name on Windows
           D-3: How to Run Scripts from Windows
           D-4: Cut, copy and paste in the Tcl Console window
           D-5: Using the Windows Clipboard
           D-6: send is not implemented on Windows
           D-7: Start-up Files tclsh.rc and wishrc.tcl
           D-8: Accessing PC serial ports from Tcl
           D-9: Using UNC file names
           D-10: Getting list of mounted drives
           D-11: Accessing the Windows Registry

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

     Windows 3.1 Issues
           W3-1: How to execute tclsh76.exe from Windows 3.1
           W3-2: Strange behaviour of exec under Win 3.1
           W3-3: Windows 3 doesn't support help contents file

           C-1: Getting the source code
           C-2: Tcl uses long file names
           C-3: Tcl was compiled with Borland C++
           C-4: Where are the .lib files?
           C-5: Creating Dynamic Extensions on Windows
           C-6: C++ and DLLs

     Compiling with Microsoft Visual C++
           M-1: How to fix the makefile for Microsoft Visual C++
           M-2: Can I use the Binary Release .DLL with my compiled
           M-3: Allocate memory with Tcl_Alloc
           M-4: How to compile with Microsoft Visual C++
           M-5: Problems with Microsoft Visual C++ 4.2 and Tcl
           M-6: Tcl and Microsoft Foundation Classes

           E-1: Expect
           E-2: Tix works on Windows.
           E-3: ODBC
           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.


   How to get Tcl/Tk For Windows

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

   Tcl/Tk 8.0 is available at

   The previous release is Tcl 7.6 patch 2 and Tk 4.2 patch 2. This release
   is available at: 6p2.exe

   Both are self-extracting archives.

   A-2: 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.

   -Eric Foster-Johnson


   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

    I-2: Wish generates a UAE error (Unhandled Win32s Exception) at startup.

   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

   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 options).

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

   -Eric Foster-Johnson

    I-3: 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 CONFIG.SYS file:

   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


   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:




    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 new 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 Windows:

   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   http://www.*-*-*.com/ ~erc/xfonts.htm.

   -Eric Foster-Johnson

   2. Windows-specific font names

   In addition to the X style font names, Tk 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,

   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: 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) 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

   c:\tcl\bin\wish42.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\wish42.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\wish42.exe" "c:\Program Files\myscript.tcl"

   -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 feed.)

   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

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

   The Tcl Console window sets up bindings that are supposed to follow the
   Windows standard of

      *Ctrl-x: cut

     * Ctrl-c: copy

     * Ctrl-v: paste

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

   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-5: 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 MS 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

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

     * 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-6: send is not implemented on Windows

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

   D-7: 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

   D-8: 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-9: Using UNC file names

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

   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-10: 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: {a:/ c:/}.

   D-11: 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.


   Windows-Specific Bugs and Problems

     B-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

    B-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 example:

   tcl> exec xyzzy
   Couldn't read output file "TMP37.$$$" for command: no such file or directory
   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 condition.

   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

   -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

    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,

   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 NT.)

   -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 m{*filter*}of the story is:

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

   -Dennis R. LaBelle

   B-3: 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-4: fileevent only supports sockets under Windows

   Fileevents are supported on Win32 platforms for sockets only. We have
   not yet found a way to discern when a file has more input than was already
   consumed. Any help or ideas will be gratefully accepted. I believe fileevent
   does not work reliably for pipes either, on Win32 platforms. I know that
   fileevent does work reliably for sockets.

   Two possible solutions:

      *"file size " works fine on NT, so you could poll for file size changes
       on the log file and read the new data as it comes in.

     * You could create a server socket in the tcl process and read from
       that in an event driven manner. Then, you could create a small program
       (written in C?) that connects to the socket. The subprogram polls
       for file size changes on the log or does a blocking read, and when
       there is data it writes it on the socket.

   -Jacob Levy

   B-5: 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

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

   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-7: 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-8: 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 application:

   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-9: 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-10: 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-11: Tk on Windows supports cursors

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

   B-12: 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-13: toplevel -container does not work

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

   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-14: 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

   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


   Windows 3.1 Issues

   W3-1: 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-2: 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-3: 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



   C-1: Getting the source code

   The Tcl7.6p2 and Tk4.2p2 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 and

   -Eric Foster-Johnson

   C-2: 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-3: Tcl was compiled with Borland C++

   Although the Tcl and Tk DLL's were generated using the Borland C++ compiler,
   it is possible to write extensions and applications in Visual C++ (or
   other compilers). There are a couple of gotchas to be aware of, however.

   First, you will need the VC++ .lib files, which can be found at

   Second, because the malloc/free supplied by Borland is not compatible
   with that supplied by Microsoft, you must not free memory allocated by
   Tcl using the Microsoft free(). Instead, you should use the Tcl_Ckfree()
   call. The most common case is uses of Tcl_SplitList.

   Additonally, you should not pass malloc'ed memory to Tcl, expecting Tcl
   to free it. If you want to allocate memory that Tcl will free, use
   Tcl_Ckalloc() instead. This will mostly affect uses of Tcl_SetResult
   (or interp->result) and the TCL_DYNAMIC flag.

   In future releases, ckalloc and ckfree will use Tcl_Ckalloc() and
   Tcl_Ckfree() instead of malloc and free, but for now you should use
   these routines directly.

   -Scott Stanton

   Note that Borland C++ users must upgrade to version 4.52 to compile Tk
   4.1 and higher. If you get an error like the following, you'll need to

   Error ..\win\tkWinWm.c 553: Undefined symbol 'WS_EX_TOOLWINDOW' in...

   C-4: Where are the .lib files?

     For Borland:
           You can generate the .lib files from the .dll files shipped with
           the binary release by using the implib.exe utility that comes
           with Borland C++. For example, to generate tcl76.lib, you would
           issue the following command:

           implib tcl76.lib tcl76.dll

     For Visual C++:
           The .lib files for Visual C++ are available on the Sun ftp site
           for the binary release. Look for:


   -Scott Stanton

   C-5: Creating Dynamic Extensions on Windows

   Version 7.6 of Tcl has the ability to dynamically load binary Tcl extensions
   at run time. We have written a sample dynamically loadable extension
   that should work on all of the platforms where dynamic loading is supported.
   This example can serve as a template for building your own extensions.

   The example is available from

           This file contains a sample loadable Tcl extension for Macintosh,
           Windows, and Unix platforms.

           Same as example.tar.Z except compressed with gzip instead of
           Same as example.tar.Z except archived with zip instead of tar
           and compress.

   -Scott Stanton

   How to build loadable extensions on Windows with the TkMsWin Extension

   Building loadable Windows extensions for Tcl still requires a DllEntryPoint
   routine (for Win32s 32-bit extensions). This routine is called when
   LoadLibrary is invoked to load the extension, and must return TRUE (after
   any specific initialization it does) to succeed for the initial load. See
   the LoadLibrary and DllEntryPoint functions in the Win32 manual for full

   In hello.c, the sample extension, I was satisfied with adding the following
   code near to the top of the file:

   #ifdef _RTLDLL
   BOOL _export WINAPI DllEntryPoint (HINSTANCE hInstance, DWORD seginfo,
   LPVOID lpCmdLine)
     /* Don't do anything, so just return true */
     return TRUE;

   Since the makefile defines _RTLDLL, and that is associated with DLLs,
   this seems a reasonable thing to do. The extension appears to load properly
   with this change.

   -Michael Schwartz

   Michael Schwartz also has an extension for Windows 3.11 users, which
   provides for some windows-specific behavior.

   The extension (so far) will asynchronously exec another windows application.
   I have tried to adhere to package constructs as well, so if you have
   done the pkg_mkIndex thing, then you should be able to do the package
   require tkmswin and get this automatically loaded. The 2nd argument seems
   to be off a byte (tkmswin exec notepad xyz.dat will try to start notepad
   with file yz.dat), but I don't think this problem is in the extension

   This command is quite crude--no thought is given to piping stdout or
   stderr, no attributes are parsed from command line switches, no new
   environment, no new starting directory, and the command itself is jammed
   in with a strcmp. Certainly nothing elegant. But, at least it works, and
   may be a place to build from.


      *load tkmswin.dll (alternative to the package require command)

     * tkmswin exec filename.exe [command line arguments]

   I called the extension Tkmswin, to allow for incorporation of other
   windows-specific features later. Tkmswin is useful set of utilities for
   emulating a number of Unix commands reasonably in the Win32s environment.
   The commands provided are (as of version of Tkmswin):

     tkmswin exec filename args
           Used to create threads for windows programs to run independently
           At this time, this is not connected to any program pipe or

           Also, the -directory and -geometry options don't seem to work
           under Win32s

     tkmswin print filename ...
           Used to send a file to the printer in "raw" format (e.g.,

           Despite the documentation on EPS, the MSWindows preamble does
           get sent to a Postscript printer, and thus a blank page is emitted
           at the end of each job.

     tkmswin rm filename ...
           Used to remove files Does not support any options, and cannot
           be used to remove directories

     tkmswin mv filename newfile or tkmswin mv file1 file2 ... dir
           Used to rename a file or set of files. Does not support any options
           or moving directories

     tkmswin cp filename newfile or tkmswin cp file1 file2 ... dir
           Used to copy a file or set of files Does not support any options
           or copying directories

     tkmswin mkdir dir1 ...
           Used to create a directory or set of directories

     tkmswin rmdir dir1 ...
           Used to remove an empty directory or set of directories

     tkmswin get_profile -section sectname [-private filename] \
     [-default defstring] [-key string] [-max maxsize]
           Used to get information from Win3.1 .INI files -private filename
           points to a particular .INI file -section sectname points to
           the proper section of the .INI file -default defstring is a string
           to return if the key is not found (default "") -key string is
           the value to search for. If omitted, a list of keys is returned
           -max maxsize is the biggest return value expected (default 1024).
           for example, the call tkmswin get_profile -section fonts would
           normally require a bigger -max.

     tkmswin set_profile -section sectname [-private filename] \
     -key keyname -value valuename
           Similarly, sets values in the .INI files.

     tkmswin version
           Returns the version of this package

     Items to go:

              *cp, rm, mv should take -f arguments (instead of always
               implementing -f)

             * Directories should be movable and removable (-r option)

             * Real windows registration services should be supported

             * Common Dialog Boxes should be supported

   You can pick up the source code for tkmswin from Michael Schwartz's home
   page at:

    http://www.*-*-*.com/ ~mschwart

   See the ATk page from this link.

   -Michael Schwartz

   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.


   Compiling with Microsoft Visual C++?

   M-1: How to fix the makefile for Microsoft Visual C++

   With Microsoft Visual C++, you need to have both a 32-bit compiler (e.g.,
   MSVC++ 2.2 or 4.0) and a 16-bit compiler (e.g., MSVC++ 1.5). You may
   then have to edit the makefiles to point to the proper directories.

   The default uses something like the following:

     MSVC++ 4.0

     MSVC++ 1.52

   -Eric Foster-Johnson

   If you're getting a problem with compiling the resources for Tcl, the
   following may help.

   The problem is that we're letting nmake define RC and CC rather than
   explicitly define them yourself. CC runs as cl.exe without an explicit
   path, so depending on your $PATH setup, it might run the wrong compiler
   version. I changed my makefile to use TOOLS32, rc32 and cc32, explicitly
   defined off of TOOLS32, and it worked fine.

   The changes made are:


   cc32 = $(TOOLS32)\bin\cl -I$(TOOLS32)\include
   rc32 = $(TOOLS32)\bin\rc


   TOOLS32   = c:\msdev

      *changed all instances of RC to rc32, CC to cc32 and TOOLS to TOOLS32

     * changed resource compiler to use -r flag.

   -John Buckman

   M-2: Can I use the Binary Release .DLL with my compiled applications?

   The binary release is compiled with Borland C++. You can build the DLLs
   from source code, or download the libraries compiled with Microsoft Visual
   C++ from the the Sun FTP server:

   -Scott Stanton and Cristian Mata

   M-3: Allocate memory with Tcl_Alloc

   If you allocate memory from within a Visual C++ program and pass that
   memory on the the Tcl DLLs, you must allocate that memory with Tcl_Alloc().

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

   M-4: How to compile with Microsoft Visual C++

   To compile Tcl with Microsoft Visual C++, I followed these steps:

      *You must have installed both MSVC++ 1.5 (16-bit compiler) and MSVC++
       2.2 or higher (32-bit compiler). I used 4.0 on Windows 95.

     * Fix the makefiles as described above, if necessary.

     * Go to the Tcl and Tk source directories. Copy to makefile
       . Do this in both directories.

     * In the Developer Studio (I'm using version 4.0), open the makefile
       in the Tcl source directory.

       Choose the Open... choice from the File menu. In the List Files of
       Type entry near the bottom, select All Files (*.*). Then, in the
       Open As: entry (near the bottom right), select Makefile. You do this
       because you want to make a new project out of an existing makefile.
       This will create a new "project" with an executable name of

       Since this is not a very good name for the Tcl interpreter, change
       makefile1.exe to tclsh.exe.

     * Now, select Rebuild All in the Build menu to compile the library
       and tclsh.exe.

     * When completed, go to the Tk directory and open its makefile the
       same way you did the Tcl directory makefile. This will create a new
       project for the Tk sources.

     * This time, rename the executable from "makefile1.exe" to wish.exe.

     * Rebuild all again to compile Tk and wish.exe.

     * When you're done, you'll need to copy tclsh.exe, wish.exe and all
       .DLL files from both the Tcl and Tk directories into your target
       directory. The .DLL files are the new dynamic link libraries you
       created with Microsoft's, instead of Borland's, C++ compiler.

   -Eric Foster-Johnson

   M-5: Problems with Microsoft Visual C++ 4.2 and Tcl

   If you're using Visual C++ 4.2 and running under Windows 95, you may
   get an error that the msvcrt.dll cannot be found. You may also have problems
   with an invalid argument error.

   You can solve your problem one of two ways:

      *Back out of VC++ 4.2 to VC++ 4.1

     * Install the msvcrt.dll that's missing (or on some Win95 systems,
       corrupted!) in your c:\windows\system directory.

    The problem is that VC++ 4.2 for some reason generates code that wants
   this DLL, and if it's not there, it won't work. And, some versions of
   Win95 are shipping without this DLL, or worse, with one that's incompatible
   with the code generated with VC++ 4.2

   -Jacob Levy

   M-6: 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   http://www.*-*-*.com/



   E-1: Expect

   Expect is in the process of being ported to Windows. Right now, the alpha
   2 version of Expect 5.21 works on Windows NT, but not Windows 95. You
   can get it from:


   E-2: Tix works on Windows

   The Tix extension has been ported to windows.

   E-3: ODBC

   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

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

   -Jose L Porcayo

   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:

   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


   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, from
    http://www.*-*-*.com/ ~jhobbs/work/tkcon/.

   E-8: OCX Extensions for Tcl

   From the Web page: Tcl75.ocx is a 32bit custom control 'wrapper' that
   exposes much of the functionality of the Tcl version 7.5 script interpreter
   to programs that are capable of using OLE automated windows controls.
   Visual Basic 4.0 is a good example of this. It can be used under Windows
   NT and Windows 95.

   Tcl OCX is available from:

    http://www.*-*-*.com/ ~farstar/Tcl75Ocx.htm

   (That's a letter "O" and not the number "0".) This Web site may be moving

   Probably requires Visual C++ 4.2 or higher.

   TOCX, another extension, allows you to use existing OCX or ActiveX controls
   in a widget-like way.

   E-9: TkTable

   tkTable 1.3, an editable 2D table/matrix widget. Supports Unix Tcl/Tk
   variants and Windows, requires Tcl7.5+/Tk4.1+, compiling is required.
   Precompiled Tk8.0a2 DLL is included.


   E-10: MDI (Muliple Document Interface)

   There is a very nice Tcl-only package called mdw-lib (Multi Document

   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 http://www.*-*-*.com/

   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

   E-13: Togl (Tk OpenGL)

   See   http://www.*-*-*.com/ ~rschultz/togl.html for
   information on Togl for NT,   http://www.*-*-*.com/ ~brianp/Togl.html
   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.


   Thanks To:
   Frederic Bonnet
   John Buckman
   Gordon Chaffee
   Joe English
   Dave Griffin
   Jon Herlocker
   Alex Hubbard
   Dennis R. LaBelle
   Gordon Lack
   Ioi Lam
   Jacob Levy
   Don Libes
   John Robert LoVerso
   Cristian Mata
   Robert Philpott
   Jose L Porcayo
   Josh Putnam
   Brian L. Rubow
   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

   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 herein.

Eric Foster-Johnson

http://www.*-*-*.com/ ~erc

Fri, 11 Aug 2000 03:00:00 GMT  
 [ 1 post ] 

 Relevant Pages 

1. Tcl/Tk on Windows Frequently-Asked Questions

2. Tcl/Tk on Windows Frequently-Asked Questions

3. Tcl/Tk on Windows Frequently-Asked Questions

4. Tcl/Tk on Windows Frequently-Asked Questions

5. Tcl/Tk on Windows Frequently-Asked Questions

6. Tcl/Tk on Windows Frequently-Asked Questions

7. Tcl/Tk on Windows Frequently-Asked Questions

8. Tcl/Tk on Windows Frequently-Asked Questions

9. Tcl/Tk on Windows Frequently-Asked Questions

10. Tcl/Tk on Windows Frequently-Asked Questions

11. Tcl/Tk on Windows Frequently-Asked Questions

12. Tcl/Tk on Windows Frequently-Asked Questions


Powered by phpBB® Forum Software