OpenCores
URL https://opencores.org/ocsvn/or1k_old/or1k_old/trunk

Subversion Repositories or1k_old

[/] [or1k_old/] [trunk/] [insight/] [tix/] [win/] [DLLDemo/] [Demo.c] - Blame information for rev 578

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
/*
2
 * Demo.c --
3
 *
4
 *      Demonstrates how to create a Windows DLL that uses Tcl/Tk and
5
 *      (optionally) Tix.
6
 *
7
 *      A Windows DLL for Tcl/TK must have three functions. Two of them
8
 *      are DLL Entry Points, required by Windows and are called when
9
 *      the DLL is loaded into Windows. The third one is a function
10
 *      called <Pkg>_Init, which is called when the DLL is loaded into
11
 *      tclsh.exe or wish.exe via the "load" command.
12
 *
13
 * DLL Entry Points:
14
 *
15
 *      For the two DLL entry points, actually only one of them is called,
16
 *      depending which compiler you are using. If you use VC++, you should
17
 *      define the function DllMain. If you use Borland C++, you should
18
 *      define the function DllEntryPoint. In this file, we just define
19
 *      both of them so that this file can be happily compiled under
20
 *      both compilers. We will just make DllEntryPoint to call DllMain(),
21
 *      which should carry any initialization actions required. In most
22
 *      cases, however, we wouldn't do any initialization and just return
23
 *      TRUE.
24
 *
25
 * <Pkg>_Init function
26
 *
27
 *      You must have a function called <Pkg>_Init, where <Pkg> is the name
28
 *      of your package. In our case, we name the package "Demo" so the
29
 *      function is Demo_Init(). It should just do the normal sort of
30
 *      initializations required by a Tcl extension (create commands,
31
 *      variables, etc). In our example, we create a command called
32
 *      "demoHello" which just returns the string "Hello Tcl/Tk World".
33
 *
34
 * Linking to the C language API of Tix
35
 *
36
 *      Nothing special needs to be done. You have to make sure the Tix
37
 *      header files are in the INCLUDE directories and like against Tix41.lib
38
 *      when you create your DLL. See the "demo_tix.dll" target in
39
 *      the makefile.bc
40
 */
41
#include <tkPort.h>
42
#include <tkWinInt.h>
43
#include <tkInt.h>
44
 
45
/*
46
 * Forward Declarations
47
 */
48
 
49
BOOL APIENTRY           DllMain _ANSI_ARGS_((HINSTANCE hInst,
50
                            DWORD reason, LPVOID reserved));
51
 
52
int                     Demo_HelloCmd _ANSI_ARGS_((ClientData clientData,
53
                            Tcl_Interp * interp, int argc, char ** argv));
54
/*
55
 *----------------------------------------------------------------------
56
 *
57
 * DllEntryPoint --
58
 *
59
 *      This wrapper function is used by Borland to invoke the
60
 *      initialization code for Tk.  It simply calls the DllMain
61
 *      routine.
62
 *
63
 * Results:
64
 *      See DllMain.
65
 *
66
 * Side effects:
67
 *      See DllMain.
68
 *
69
 *----------------------------------------------------------------------
70
 */
71
 
72
BOOL APIENTRY
73
DllEntryPoint(hInst, reason, reserved)
74
    HINSTANCE hInst;            /* Library instance handle. */
75
    DWORD reason;               /* Reason this function is being called. */
76
    LPVOID reserved;            /* Not used. */
77
{
78
    return DllMain(hInst, reason, reserved);
79
}
80
 
81
/*
82
 *----------------------------------------------------------------------
83
 *
84
 * DllMain --
85
 *
86
 *      DLL entry point.
87
 *
88
 * Results:
89
 *      TRUE on sucess, FALSE on failure.
90
 *
91
 * Side effects:
92
 *      None.
93
 *
94
 *----------------------------------------------------------------------
95
 */
96
 
97
BOOL APIENTRY
98
DllMain(hInstance, reason, reserved)
99
    HINSTANCE hInstance;
100
    DWORD reason;
101
    LPVOID reserved;
102
{
103
    /*
104
     * If we are attaching to the DLL from a new process, tell Tk about
105
     * the hInstance to use. If we are detaching then clean up any
106
     * data structures related to this DLL.
107
     */
108
 
109
    return(TRUE);
110
}
111
 
112
 
113
int
114
Demo_HelloCmd(clientData, interp, argc, argv)
115
    ClientData clientData;
116
    Tcl_Interp * interp;
117
    int argc;
118
    char ** argv;
119
{
120
    Tcl_AppendResult(interp, "Hello Tcl/Tk World", NULL);
121
 
122
    return TCL_OK;
123
}
124
 
125
int _export
126
Demo_Init(interp)
127
    Tcl_Interp * interp;
128
{
129
    Tcl_CreateCommand(interp, "demoHello", Demo_HelloCmd, NULL, NULL);
130
 
131
    return TCL_OK;
132
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.