[python-win32] Re: how to load 2 python COM DLLs in single app?
Thomas Heller
theller at python.net
Fri Nov 26 17:25:26 CET 2004
Niki Spahiev <niki at vintech.bg> writes:
> SUCCESS!
>
> Renaming scheme works for me (TM) and i can load 2 Inprocess COM servers.
> Attached patch is for py2exe 0.54
Cool!
> Option --unique=MN turns on renaming. MN are any 2 characters valid
> for filename.
Are two characters enough? Four would be better, imo.
> No debug-python support (_d.pyd).
>
> Thomas will you include it in py2exe?
My impression is that the patch still needs some work.
First, it didn't apply completely to the CVS version - that's not your
fault, I've made other changes in the meantime.
Second, I had to make this change so that the unique option accepts a
parameter:
> + ("unique", 'u',
> + "patch all DLLs to be unique"),
must be changed to
> + ("unique=", 'u',
^
> + "patch all DLLs to be unique"),
Third, it doesn't work for other cases ;-). It tries to patch all dlls,
except those that start with 'tcl' or 'tk'. For the 'simple' sample in
the distribution, it fails patching the wxwindows dll, plus the
w9xpopen.exe helper.
IMO it would be better to first check whether a dll or an exe
dynamically links to python23.dll, and only if it does the renaming and
patching would take place. For finding out the dlls an image links to,
the py2exe_util extension's 'depends' function could be used.
Then, if I understand correctly, you simple replace all occurrences of
'python23.dll' in the image by the changed name. Wouldn't this be
required to be case sesitive? And wouldn't it be required to only make
this change in the import table (maybe you take care of this by only
replaing the first string you find).
Other comments:
> +BOOT_UNIQUE = """
> +def __load(name,ext):
> + import imp, sys
> + dirname = sys.prefix
> + path = dirname + '/' + name + ext
> + mod = imp.load_dynamic(name, path)
> +## mod.frozen = 1
> +__load('zlib','%(UN)s.pyd')
> +__load('pywintypes','%(UN)s.dll')
> +__load('pythoncom','%(UN)s.dll')
> +del __load
> +"""
Why zlib? It may or may not be included...
All in all, this is pretty cool, but still needs work, and there are a
lot of details to get correct.
Thanks,
Thomas
More information about the Python-win32
mailing list