[Python-Dev] DLL in the system directory on Windows.

James C. Ahlstrom jim@interet.com
Thu, 06 Apr 2000 11:48:50 -0400


Guido van Rossum wrote:

> But, I still don't understand why Perl/COM doesn't need a DLL in the
> system directory.  Or is it just because they change PATH?

Here is some generic info which may help, or perhaps
you already know it.

If you have a DLL head.dll or EXE head.exe which needs
another DLL needed.dll, you can link needed.dll
with head, and the system will find all data and
module names automatically (well, almost).  When head
is loaded, needed.dll must be available, or head will
fail to load.  This can be confusing.  For example, I
once tried to port PIL to my new Python mini-GUI model,
and my DLL failed.  Only after some confusion did I
realize that PIL is linked with Tk libs, and would fail
to load if they were not present, even though I was not
using them.

I think what Mark is saying is that Microsoft now has
an option to do delayed DLL loading.  The load of needed.dll
is delayed until a function in needed.dll is called.  This
would have meant that PIL would have worked provided I
never called a Tk function.  I think he is also saying
that this feature can only trap function calls, not
pointer access to data, so it won't work in the context
of data access (maybe it would if a function call came first).
Of course, if you access all data through a function call
GetMyData(), it all works.

As an alternative, head.[exe|dll] would not be linked with
needed.dll, and so needed.dll need not be present.  To
access functions by name in needed.dll, you call LoadLibrary
or LoadLibraryEx to open needed.dll, and then call
GetProcAddress() to get a pointer to named functions.  In
the case of data items, the pointer is dereferenced twice,
that is, data = **pt.  Python uses this strategy to load
PYD's, and accesses the sole function initmodule().  Then
the rest of the data is available through Python mechanisms
which effectively substitute for normal DLL access.

The alternative search path available in LoadLibraryEx
only affects head.dll, and causes the system to look in
the directory of needed.dll instead of the directory
of the ultimate executable for finding other needed DLL's.

So on Windows, Python needs PYTHONPATH to find PYD's,
and if the PYD's need further DLL's those DLL's can
be in the directory of the PYD, or on the usual DLL
search path provided the "alternate search path"
is used.

Probably you alread know this, but maybe it will help
the Windozly-challenged follow along.

JimA