Using COM constants on under IIS ASP.

Alex Martelli aleaxit at yahoo.com
Wed Oct 25 09:31:29 EDT 2000


"Syver Enstad" <syver at cyberwatcher.com> wrote in message
news:UnAJ5.14550$W31.220361 at news1.online.no...
> Does anybody know how to access the constants of COM objects created with
> Server.CreateObject. I tried using the global.asa file to accomplish this,
> but it doesn't seem to work.

As long as you've run makepy on the type-library of the object you're
creating, all constants defined in that library will be available as
attributes of win32com.client.constants when objects defined in that
library are created.

See, for more details:
http://www.oreilly.com/catalog/pythonwin32/chapter/ch12.html
which is a sample-chapter from the "Python Programming on
Win32" book, and happens to be exactly the one on "Advanced
Python and COM".  But I recommend you purchase & read the
whole book.

There may be ways to get even at the constants of an object whose
typelibrary has NOT been subjected to makepy (as long as the object
is "kind" enough to reveal upon request the type-library it belongs
to... which is a nice thing for COM objects to do, but not a
mandatory one [e.g., Python-implemented COM objects typically
have nothing to do with type-libraries, thus give no 'type-info'
when it's asked for...]).  But that's a "meta-advanced" issue,
and just running makepy is handier & better 99.44% of the time.

>From Pythonwin, Tools/COM Makepy utility will present a list of
registered type-libraries; just pick the one you want to use
from Python (this must be done on the machine where your Python
scripts will run from...).  Running from the command line, you
can also use the -i option (example picking 'Acrobat Control for
ActiveX' from the interactive list presented):

D:\Python20\win32com\client>python makepy.py -i
Acrobat Control for ActiveX
 {CA8A9783-280D-11CF-A24D-444553540000}, lcid=0, major=1, minor=3
 >>> # Use these commands in Python code to auto generate .py support
 >>> from win32com.client import gencache
 >>> gencache.EnsureModule('{CA8A9783-280D-11CF-A24D-444553540000}', 0, 1,
3)

D:\Python20\win32com\client>

the call to gencache.EnsureModule will generate the needed support
for the typelibrary, if needed.


Alex






More information about the Python-list mailing list