Re: C extension Clarification

From: David Gravereaux (davygrvy_at_pobox.com)
Date: 09/08/04


Date: Wed, 08 Sep 2004 11:56:59 -0700

noorul.ameen@gmail.com (Noorul Ameen) wrote:

>Dear Folks,
>
> I have a C code which is for some driver. I need to add it as tcl
>command. What needs to do. Is that we need to recompile the Tcl Source
>for it.
>
>Thanks in advance.
>
>
>Thanks & Regards,
>Noorul Ameen T

#include "tcl.h"
Tcl_ObjCmdProc MyCmd;

int
MyCmd (ClientData clientData, Tcl_Interp *interp, int objc,
        struct Tcl_Obj * CONST objv[])
{
    Tcl_SetObjResult(interp, Tcl_NewStringObj("hi there!", -1));
    return TCL_OK;
}

#undef TCL_STORAGE_CLASS
#define TCL_STORAGE_CLASS DLLEXPORT

EXTERN int
Mycmd_Init (Tcl_Interp *interp)
{
#ifdef USE_TCL_STUBS
    if (Tcl_InitStubs(interp, TCL_VERSION, 0) == 0L) {
        return TCL_ERROR;
    }
#endif
    Tcl_CreateObjCommand(interp, "mycmd", MyCmd, 0L, 0L);
    return TCL_OK;
}

compile it to a shared library with -DUSE_TCL_STUBS and linking to the
stubs library. name it mycmd.dll or mycmd.so or whatever your naming
format on your OS is.

-- 
David Gravereaux <davygrvy@pobox.com>
[species: human; planet: earth,milkyway(western spiral arm),alpha sector]


Relevant Pages

  • interface tcl to mingw dll which uses a msvc dll
    ... I'm not sure if this is a mingw or tcl problem. ... int ljackCmdHello (ClientData clientData, Tcl_Interp *interp, int ... Ljacktcl_Init(Tcl_Interp* interp) ... unsigned long *servicePackMajor, ...
    (comp.lang.tcl)
  • Re: C++/TCL Need Solution to Compile Error c2784
    ... ConnectCmd (ClientData clientData, Tcl_Interp *interp, ... DisconnectCmd (ClientData clientData, Tcl_Interp *interp, ... Do I have to tell the compiler to load the ...
    (comp.lang.tcl)
  • Re: Need help with loading .SO file
    ... int GetText(ClientData clientData, ... int Proc_Init(Tcl_Interp *interp) ... Tcl_CreateCommand(interp, "gettext", GetText, ... reason to stay with Tcl 8.3 you should try to use a recent Tcl like Tcl ...
    (comp.lang.tcl)
  • Re: C++/TCL Need Solution to Compile Error c2784
    ... I looked for a solution to repackage the DLL to be TCL ... ConnectCmd (ClientData clientData, Tcl_Interp *interp, ... DisconnectCmd (ClientData clientData, Tcl_Interp *interp, ...
    (comp.lang.tcl)
  • Re: C++/TCL Need Solution to Compile Error c2784
    ... ConnectCmd (ClientData clientData, Tcl_Interp *interp, ... DisconnectCmd (ClientData clientData, Tcl_Interp *interp, ... How many boards would the Mongols hoard if the Mongol hordes got bored? ...
    (comp.lang.tcl)