DoctorBurp
DoctorBurp

Reputation: 63

Loading a Tcl package written in C (DLL) from .NET assembly

I'm writing in C# and want to use tcl.

After searching I found Tcl/Csharp project which does the job, however is missing a package that allows it to work with the registry. I have the package in a form of dll file but I"m unable to load it.

class Program 
{
    static void Main(string[] args) 
    {
        Interp interp = new Interp();

        interp.eval("puts hello world");     // Works
        interp.eval("load tclreg12.dll");    // Throws TclException Invalid command name "load"
        interp.eval("package req registry"); // Throws TclException "cant find package registry"

        TclObject result = interp.getResult();
        Console.WriteLine(result);

        interp.dispose();
    }
}

How can I use this package?

Upvotes: 1

Views: 1033

Answers (1)

kostix
kostix

Reputation: 55453

As M.Babcock correctly pointed out, that Tcl/Csharp package you're using is just an attempt to implement a Tcl interpreter on top of the .NET stack, but the load command is highly special as it (in the "real" Tcl) is intended to load Tcl packages written in C, and such packages are supposed to use the C API exposed by the Tcl runtime itself. This C API is quite comprehensive and, naturally, making a pure .NET code properly emulate all that C API stuff would be a huge undertaking, if at all possible.

Since Windows registry manipulations are trivially done in .NET, I suppose you have a large legacy program written in Tcl at hand, which you need to call from your .NET program (as you probably estimated that porting that program would be more hassle than making it run as is). If this is true, I would have taken one of these routes:

  • Turn your program into a starpack and bundle the resulting executable file along with your "host" program, then just execute it as a separate program. (That file would be single and have no special dependencies.)
  • Write a special wrapper assembly which would use P/Invoke to load the real Tcl runtime (Tcl's shell, tclshXY.exe is just a thin program, and the real thing is tclXY.dll plus a set of library files, and this is the DLL you're supposed to load). Then your code could pass the Tcl runtime a script (in the form of the string) which would load and execute the actual Tcl program you need to run.

Upvotes: 2

Related Questions