win32com and makepy

Sean Laurent slaurent at sonicfoundry.com
Fri Feb 23 15:54:41 EST 2001


Howdy  All,
I'm having a strange problem with win32com.client.Dispatch().  I used
win32com\client\makepy.py to successfully generate Python sources.
Unfortunately, after I call win32com.client.Dispatch(), the object I
get back is of type "COMObject" instead of one of the generated
classes.

In particular, I'm trying to interact with Microsoft Windows Installer
Service (known as MSI) - the typelibrary is named "Microsoft Windows
Installer Object Library" and the PROGID is
"WindowsInstaller.Installer".

Using win32com\client\makepy.py:
makepy -i "Microsoft Windows Installer Object Library"
Microsoft Windows Installer Object Library
{000C1092-0000-0000-C000-000000000046}, lcid=1033, major=1, minor=0
>>> # Use these commands in Python code to auto generate .py support
>>> from win32com.client import gencache
>>>gencache.EnsureModule('{000C1092-0000-0000-C000-000000000046}',1033, 1, 0)

Looking in win32com\gen-py, the appropriate file _does_ exist:
000C1092-0000-0000-C000-000000000046x1033x1x0.py
and it does contain the correct class definitions.

Then, in my code:
>>> i = win32com.client.Dispatch("WindowsInstaller.Installer")
>>> i
<COMObject WindowsInstaller.Installer>
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Voila!  There's the problem.  According to the docs, this really
should be something more like:
<win32com.gen_py.Microsoft Windows Installer.Installer>

Furthermore, if I call a method which should create another object,
things get even worse:
>>> db = i.OpenDatabase("d:\\temp\\test.msi", 0)
>>> db
<COMObject <unknown>>
^^^^^^^^^^^^^^^^^^^^^
Again, this should be something more like:
<win32com.gen_py.Microsoft Windows Installer.Database>


However, if I try this with Microsoft Word, everything works great!
makepy -i "Microsoft Word 9.0 Object Library"
Microsoft Word 9.0 Object Library
{00020905-0000-0000-C000-000000000046}, lcid=0, major=8, minor=1
>>> # Use these commands in Python code to auto generate .py support
>>> from win32com.client import gencache
>>> gencache.EnsureModule('{00020905-0000-0000-C000-000000000046}', 0, 8, 1)

>>> w = win32com.client.Dispatch("Word.Application")
>>> w
<win32com.gen_py.Microsoft Word 9.0 Object Library._Application>


*arrrgghhh*

Any bright ideas as to what's going wrong here?

----------
Sean Laurent
Engineer -Install
Sonic Foundry, Inc.
slaurentNOSPAM at sonicfoundryNOSPAM.com
----------



More information about the Python-list mailing list