Hi
I would like to know how could we communicate between VC++ and TCL.
I've tried it using SWIG. that was call for C++ function by TCL.
Can a C++ give a call to TCL module.

What is the ICE?
Is it related to C++ and TCL communication somehow?

Dani AI

Generated

Short answer: a VC++ program can both execute Tcl code and expose C++ functions to Tcl. Two practical patterns are (A) embed the Tcl interpreter via the Tcl C API so the program evaluates scripts and registers C++ callbacks, or (B) run a Tcl interpreter as a separate process and exchange data over pipes or sockets when linking extra libraries is not permitted. Earlier replies by and pointed out library/tool options; below are concrete, implementation-oriented notes for embedding and for a no-linking alternative.

A minimal embed workflow (create interpreter, register a command, eval a script) looks like this:

#include <tcl.h>

static int MyCmd(ClientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) {
    if (objc != 2) { Tcl_WrongNumArgs(interp,1,objv,"msg"); return TCL_ERROR; }
    const char *msg = Tcl_GetString(objv[1]); /* handle in C++ code */
    Tcl_SetObjResult(interp, Tcl_NewStringObj("OK",-1));
    return TCL_OK;
}

int main(int argc, char **argv) {
    Tcl_FindExecutable(argv[0]);
    Tcl_Interp *interp = Tcl_CreateInterp();
    if (Tcl_Init(interp) != TCL_OK) return 1;
    Tcl_CreateObjCommand(interp,"mycmd",MyCmd,NULL,NULL);
    Tcl_Eval(interp,"puts [mycmd Hello]");
    Tcl_DeleteInterp(interp);
    Tcl_Finalize();
    return 0;
}

If adding the Tcl runtime to the build is forbidden, the safer route is out-of-process IPC: launch a tclsh (or a small Tcl-hosting helper) with stdin/stdout redirected (CreateProcess + pipes on Windows), send commands, read responses, and use a simple framing protocol (length prefix or sentinel) to avoid partial reads. TCP sockets are an alternative if both processes can open ports.

Troubleshooting/caveats: call Tcl_FindExecutable early, link the import library that matches the Tcl DLL and MSVC runtime, prefer the Tcl_Obj API for performance and correctness, always check TCL_OK/TCL_ERROR results, and avoid sharing one interpreter concurrently across threads. If corporate policy truly bars any external runtime, either request an exception for the Tcl runtime or port the required logic into native C++.

Recommended Answers

All 4 Replies

If you want a third party library for interfacing between C++ and TCL then maybe you should look here
http://cpptcl.sourceforge.net/

As for your second part of the question you havent as such mentionend what exactly is ICE otherwise i would have definately said something.

Hope it helped, bye.

What is the ICE?
Is it related to C++ and TCL communication somehow?

ICE is a Tcl compiler. The compiler translates Tcl code into C code, which can then be compiled together with a special Tcl library to produce a single executable.

hi
thanks for helping:lol:

Will you tell me the site from which i could download ICE or a link which help me for using it?
:rolleyes:

I am not allowed to use any third party lib or software unless specified

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.