Skip to content
Tcl Source Code Attachment Details
Login

Attachment Details

Overview

Artifact ID: 733dde9d36dde8ff4247e973276901da5b387b2d
Ticket: 615304ffffffffffffffffffffffffffffffffff
Date: 2002-10-02 22:08:23
User: davygrvy
Artifact Attached: 760f3e2fbe0c28104fa315fcb9c32eb8721d8cd8
Filename:bug615304.c
Description:test case from bug description.
Content:
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
#define USE_TCL_STUBS
#include "tcl.h"

#define VERSTR	    STRINGIFY(JOIN(TCL_MAJOR_VERSION,TCL_MINOR_VERSION))

/* make sure we link to the matching stubs library */
#pragma comment (lib, "tclstub" VERSTR ".lib")

/* make sure we load the matching dll from the proper place */
#define TCLPATH	    "c:\\progra~1\\tcl\\bin\\"
#ifdef _DEBUG
#   define TCLDLLNAME  TCLPATH "tcl" VERSTR "d.dll"
#else
#   define TCLDLLNAME  TCLPATH "tcl" VERSTR ".dll"
#endif

#include <windows.h>

HMODULE hTclModule;
typedef Tcl_Interp *(*LPFN_createInterpProc) ();
LPFN_createInterpProc createInterpProc;


Tcl_Interp *
LoadIt(const char *application)
{
    Tcl_Interp *interp;

    hTclModule = LoadLibrary(TCLDLLNAME);
    if (hTclModule == NULL) {
	puts("can't load " TCLDLLNAME);
	return NULL;
    }

    createInterpProc = (LPFN_createInterpProc)
	    GetProcAddress (hTclModule, "Tcl_CreateInterp");
    if (createInterpProc == NULL) {
	puts("can't find Tcl_CreateInterp()");
	return NULL;
    }

    // make an interpreter.
    interp = createInterpProc();

    // initilize our local Stubs table.
    Tcl_InitStubs(interp, TCL_VERSION, 0);

    // setup the library and encoding paths and all that hidden stuff.
    Tcl_FindExecutable(application);

    if (Tcl_Init(interp) != TCL_OK) {
	puts(Tcl_GetStringResult(interp));
	return NULL;
    }

    return interp;
}

void
UnloadIt(Tcl_Interp *interp)
{
    Tcl_DeleteInterp(interp);
    Tcl_Finalize();
    FreeLibrary(hTclModule);
}

int
main (int argc, char *argv[])
{
    Tcl_Interp *interp;
    
    interp = LoadIt(argv[1]);
    if (interp == NULL) {
	return 1;
    }

    // do work here with Tcl.
    Tcl_Eval(interp, "puts stdout \"hello from interp #1\"");

    UnloadIt(interp);

    // Do it again.
    interp = LoadIt(argv[1]);
    if (interp == NULL) {
	return 1;
    }

    // do work here with Tcl.
    Tcl_Eval(interp, "puts stdout \"hello from interp #2\"");

    UnloadIt(interp);

    return 0;
}