Re: Question about loading a DLL
- From: Ron Fox <fox@xxxxxxxxxxxx>
- Date: Thu, 16 Aug 2007 06:43:58 -0400
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, IWould work, same folder as the tclsh.exe or wish.exe you use is a simple
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?
bet. Using an absolute path for the dll when using load should also work.
or it is the problem ofMight be if you don't have an appropriate Tcl init function in your dll
the dll file itself?
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
- Follow-Ups:
- Re: Question about loading a DLL
- From: mike . hfzhang
- Re: Question about loading a DLL
- References:
- Question about loading a DLL
- From: mike . hfzhang
- Re: Question about loading a DLL
- From: Michael Schlenker
- Re: Question about loading a DLL
- From: mike . hfzhang
- Question about loading a DLL
- Prev by Date: Managing reusable code for multiple Tcl applications
- Next by Date: Re: What's the most important thing lacking in your Tcl toolbox?
- Previous by thread: Re: Question about loading a DLL
- Next by thread: Re: Question about loading a DLL
- Index(es):
Relevant Pages
|
Loading