![]() |
|
|
You know how to combine Tcl/TK and C - maybe by using the examples I provide on another page? But now you want to put the Tcl scripts together with your C code into a single application (not needing any scripts at run time)? Then (X)MkTclApp (which probably stands for "make a tcl application", for the "x" see below) is one of the tools suitable for this purpose. (Certainly another option is SWIG. Go to www.swig.org to find out for yourself.)
The MkTclApp home page is at www.hwaci.com/sw/mktclapp/ and its author is D. Richard Hipp.
If you download it, you get the source file mktclapp.c together with a Tcl
script xmktclapp.tcl and the documentation. You can get an executable for Windows, but I
would not recommend it: when I got it, it didn't reflect the current version of
mktclapp.c. Besides, it's so easy to make your own executable: No need for a makefile,
just go to the respective directory, open a console and issue
bcc32 mktclapp.c
which will result in mktclapp.exe.
An extremely useful addition to MkTclApp is XMkTclApp - a GUI extension to MkTclApp in form of a Tcl/TK script. MkTclApp is designed to be controlled by command line options (or using a config file containing those options). This is perfectly ok - but with XMkTclApp life is a lot easier. The documentation covers both: MkTclApp and XMkTclApp. As far as Windows is concerned it talks about using the Cygwin compiler and specific DLLs. As a Borland user these parts are not too important for you.
I integrated (X)MkTclApp into my normal working environment by using the following batch file (this file is in a directory on my path).
@echo off
rem
rem Add the path to mktclapp.exe so it can be called by xmktclapp.tcl
rem
set path=d:\devtools\tcl\mktclapp;%path%
rem
rem Now call xmktclapp.tcl, that is call wishxx and tell it what file
rem to load.
rem Note: If wishxx's directory is not on your path, you will have to
rem call wish with the full path
rem
wish83 d:\devtools\tcl\mktclapp\xmktclapp.tcl %1 %2 %3 %4 %5
With this batch file in place I can stay in my current working directory and am still able to activate XMkTclApp, including parameters if needed.
You should preserve the directory structure when unzipping the examples. They all have the same structure:
They contain a readme.txt with specific information.
They contain a makefile (makefile.bc) usable for the Borland compiler.
They contain a file xxx.mta: A file created by XMkTclApp, provided for
your convenience.
If you start XMkTclApp with the current directory being the example's respective source
directory, XMkTclApp fill find this file and re-read the options of its last activation.
So everything should already be set up: Call XMkTclApp, click on the Build
button, call make and start the example.
Again, these examples are primarily targeted at users of Borland compilers, but since they do not consist of a large number of files, it should be straight forward to construct a project file (or whatever it is called on your platform) for each of them. If not already done, Borland users will have to create appropriate .LIB files for the Tcl and TK DLLs as outlined here.
All examples are taken from the (X)MkTclApp documentation. The names I used for the directories closely reflect the title of the respective chapter there.
hello world: One TK script, which in the end is turned into a stand-alone executable. No need for the end user to have Tcl installed (but you will probably have to provide the Tcl/TK DLLs).
Adding More Tcl Code: The previous example continued: You are now working with two TK files.
Adding In Some C Code: As the name implies, example (1) plus C.
Implementing New Tcl Commands In C: A little TK application that can add two numbers, either using a Tcl proc or using an external C funtion.
Exec Tcl Commands From C: An example for the opposite direction: Calling a Tcl proc from your C code.
The (X)MkTclApp documentation contains more code samples, but I hope that the five examples above cover the basics.
Another aspect of combining Tcl and C is the passing of data between these two worlds. I wrote two small examples on how to transfer (Tcl) lists - a widely used data structure in Tcl scripts - in either direction.
Let's see, how many users are interested in this topic. You are visitor 3232 since Dec. 4, 2000.
Things change fast these days. Want to be informed if changes had been necessary (bugs discovered, new version of ...) or additional material is available (e.g. not only C & Tcl, but also VCL & Tcl) ?
Version info: All examples (if applicable) are based on Tcl/TK 8.3.2, Borland C++ 5.5 (or C++ Builder 5) and MkTclApp 3.9.
Copyright © Helmut Giese, email: hgiese@ratiosoft.com
Parkstr. 41, 34119 Kassel, Tel.: 0561 - 766 59 50, Fax: 0561 - 766 59 51
Königstor 59, 34119 Kassel, Tel.: 0561 - 739 35 30, Fax: 0561 - 739 35 31
Web Design von Bianca Engler: email
internet