TCL calls a c++ programm

From: Christian Galbavy (slate_at_sbox.tugraz.at)
Date: 10/30/04

  • Next message: James A. Littlefield: "Modbus Extension....."
    Date: Sat, 30 Oct 2004 14:16:45 +0200
    
    

    Hello!

    My name is Christian Galbavy. Several weeks ago, I asked in a tcl-forum
    about
    the problem to combine a tcl program with a c++ progam. You have sent me the
    answer below. Thank you very much for that and sorry for the long waiting
    time
    until my answer. I have been still very busy with the c++ program, but it is
    working now and so I have to do the interface.
    I have read the articles, which you have sent me. Unfortunately there
    is a lot,
    which I do not understand. I have not worked with Fortran yet.
    I do not understand, which way is the better one for my case:
    .) Take the C++ program for the main program and call the tcl script in it
    or
    .) Take the tcl script as the main program, which calls the c++ program
    I also do not really know, which is the best way to communicate between
    the two
    programs (file-events with buffers, use of a special package, ...)
    I hope you can help me with this questions a little bit.

    Perhaps you could send me a little example, which I have prepaired.
    I have a little c++ program, which stores an integer. It provides a
    function to
    increase the integer.
    Then I have a little tcl-script with a GUI, where this integer is shown.
    There
    is also a little button, which increases the shown integer.
    So there should be the following function. When you start the
    tcl-sript, the c++
    program is started too. The tcl script calls the getInteger-Function in
    the c++
    program and shows the integer in the label. When you click the button, the
    tcl
    script calls the incrInteger-Function and then the getInteger-Function again
    and updates the string of the label.
    Or perhaps the other way (to call the tcl script with the c++ program is
    better?).

    Here is the code of the small example-tcl-program:
    ********************
    #package required: TK

    # little integer program

      wm geom . 250x150+340+280

      set integer 0
    # here should be some function, which starts the c++ program

    proc getInteger {} {

    # Here should be a procedure, which calls the getInteger-Function from
    # the c++ program.
      return "Integer"
    }

    proc incrInteger {} {

    # Here should be a procedure, which calls the incrInteger-Function from
    # the c++ program.
    }

    proc upDateLabel {} {
      .integer_value configure -text [getInteger]
    }

    button .incr_button -text "incr" -command "incrInteger;upDateLabel"
    label .integer_value -text [getInteger]

    pack .incr_button
    pack .integer_value
    ************************

    And here is the code of the small c++ example program:
    ************************
    #include <iostream>
    #include <stdlib.h>

    using namespace std;

    class MyInteger {
    public:
      MyInteger();

      virtual ~MyInteger();

      int my_integer;

      void incrInteger();

      int getInteger();
    };

    MyInteger::MyInteger()
    {
      my_integer = 1;
    }

    MyInteger::~MyInteger()
    {
    }

    void MyInteger::incrInteger()
    {
      my_integer++;
    }

    int MyInteger::getInteger()
    {
      return my_integer;
    }

    int main(int argc, char *argv[])
    {
      MyInteger test_integer;
      cout << test_integer.getInteger() << endl;
      test_integer.incrInteger();
      cout << test_integer.getInteger() << endl;

      system("PAUSE");
      return 0;
    }
    **************************

    So there is really a lot, which is not clear to me.
    Thank you very much for any help.

    Christian Galbavy

    Zitat von Cameron Laird <claird@lairds.us>:

    [Zitattext verstecken]
    > In article <41532384$0$21764$91cee783@newsreader02.highway.telekom.at>,
    > Christian Galbavy <slate@sbox.tugraz.at> wrote:
    >> Hello!
    >>
    >> I hope somebody can help me here. I have a GUI in TCL/TK. I also have a
    very
    >> complex c++ program, and I want to combine these two programs. Is there a
    >> posibility to call a c++ program in TCL and, more important, to
    communicate
    >> between the pograms. For example:
    >> I want to start the program, which goes into an idle state. Then I want
    to
    >> call several functions of the c++ program, which compute several lists of
    >> integers and now I want to display them in the GUI. In the end I call a
    >> stop-function for the c++ program. I hope there is a possibility to do
    this.
    > .
    > .
    > .
    > More than "a possibility", this is the sort of requirement at
    > which Tcl excels. Many of us do this sort of thing, in all
    > sorts of combinations, to the point that the subject is less
    > under-documented than many others.
    >
    > I *think* you have in mind that your C++-coded program will
    > continue its life as a stand-alone executable, invoked and
    > controlled "externally" by Tcl/Tk. This is a fine choice, one
    > likely to lead quickly to success. You might like to start
    > reading <URL: http://wiki.tcl.tk/3999 > and <URL:
    > http://www.itworld.com/AppDev/4061/swol-0105-regex/ >. Notice
    > that in preserving your complex program as a stand-alone
    > executable, executing as its own process, you render the
    > language of its coding irrelevant--what you read about programs
    > coded in Fortran or C applies equally well to your program.
    >


  • Next message: James A. Littlefield: "Modbus Extension....."
  • Quantcast