Re: Question about loading a DLL



Then when all is said and done, you can also expose a pacakge
in the dll (Tcl_PkgProvide), create an pkgIndex.tcl file that
tells the package loader how to find/load the package, and
then put all of that in say c:\Tcl\lib\yourpackagename

Then you can load/initialize the dll via:

package require yourpackagename

This is probably all preferable to the load command, and
will allow you to ditch the absolute pathing. So in summary:
- load has no path to search
- load and the package load system (uses load) all require
an initialization function for the dll.
Below is an extract from the load command man page describing this;
(apologies about the formatting).

Once the file has been loaded into the applicationâs address space, one of two
initialization procedures will be invoked in the new code. Typically the iniâ[m
tialization procedure will add new commands to a Tcl interpreter. The name of
the initialization procedure is determined by packageName and whether or not
the target interpreter is a safe one. For normal interpreters the name of the
initialization procedure will have the form pkg_Init, where pkg is the same as
packageName except that the first letter is converted to upper case and all
other letters are converted to lower case. For example, if packageName is foo
or FOo, the initialization procedureâs name will be Foo_Init.

If the target interpreter is a safe interpreter, then the name of the initialâ[m
ization procedure will be pkg_SafeInit instead of pkg_Init. The pkg_SafeInit
function should be written carefully, so that it initializes the safe interâ[m
preter only with partial functionality provided by the package that is safe
for use by untrusted code. For more information on Safe-Tcl, see the safe manâ[m
ual entry.

The initialization procedure must match the following prototype:
typedef int Tcl_PackageInitProc(Tcl_Interp *interp);

- See the man page for pkg_mkIndex for information about making indices
and generally useful information about packaging. This should be in
help files for ActiveTcl if that's what you are using.




RF


mike.hfzhang@xxxxxxxxx wrote:
On Aug 15, 3:00 pm, Michael Schlenker <schl...@xxxxxxxxxxxxxxxx>
wrote:
mike.hfzh...@xxxxxxxxx schrieb:> Hi There,
I got a question about loading a DLL(dynamic link library) in TCL, I
created a simple DLL in VC++ 2005, the name of the file is "test.dll".
I put this file in the folder :" c:\Tcl\lib". However, when I try to
use the following command to load this dll,
%load test.dll
I got error message: "can not open test.dll libary, can not be found
in library path"
So should I put the dll in a specific folder?
Would work, same folder as the tclsh.exe or wish.exe you use is a simple
bet. Using an absolute path for the dll when using load should also work.

or it is the problem of
the dll file itself?
Might be if you don't have an appropriate Tcl init function in your dll
that is exported (__declspec(dllexport) Init_test(...) ), but that would
be a different error message IIRC. You cannot really load arbitrary dlls
with the Tcl load command, it expects an Init function.

Take a look at the sampleextension in cvs
(http://wiki.tcl.tk/sampleextension)
to see whats needed. (it uses autoconf though, even if it can build with
VC when passed the right flags).

Michael

Hi there,
I tried :
load c:\tcl\lib\test.dll

it seems to find the dll file but output a message:
"couldn't find procedure Test_Init"

So I think you guys are right, then how can I create the procedure
Test_Init in my VC++ 2005 code?


Mike

.



Relevant Pages

  • Re: embedded tcl thread
    ... Have you created a package? ... You load a DLL? ... Kevin Kenny presented a good solution which I now use in my ...
    (comp.lang.tcl)
  • Re: Loading Packages
    ... > I wrote a dll in C called transmitReceive.dll. ... > package and a Receive package. ... > Is there a tcl load method where I can use two packages in a dll at the ... If you load the first package, it probably registers both packages with ...
    (comp.lang.tcl)
  • Re: GUI acts dead
    ... Is there a way to load the Tk part directly from a Tcl interpreter, so I won't have to load the Tk dll myself? ... "package require Tk" ...
    (comp.lang.tcl)
  • Re: GUI acts dead
    ... Gernot Frisch schrieb: ... Is there a way to load the Tk part directly from a Tcl interpreter, so I won't have to load the Tk dll myself? ... "package require Tk" ...
    (comp.lang.tcl)
  • Re: running a service/driver/application upon startup
    ... debug version of the image is too large to load onto the device. ... I ran dumpbin/exports on the finger dll and saw the required function names: ... > theories as to why it's not getting loaded but just doing 'services load ...
    (microsoft.public.windowsce.embedded)

Loading