Problem setting COM property using win32com
Mark Hammond
mhammond at skippinet.com.au
Thu Apr 10 20:41:56 EDT 2003
The problem will be that the COM object you are using does not report
any type information at runtime (it should). Thus, we have no way of
associating the object with the makepy data.
Green, Gregory P wrote:
> I missed the last line in your example code:
>
> so if I do (using the EnsureModule line):
>
> prmidattrs = MyModule.ISmRecordList()
>
> I get:
> Traceback (most recent call last):
> File "example.py", line 43, in ?
> prmidattrs = MyModule.ISmRecordList()
> File "C:\PYTHON22\lib\site-packages\win32com\client\__init__.py", line 310, in __init__
> oobj = pythoncom.new(self.CLSID) pywintypes.com_error: (-2147221164, 'Class not registered', None, None)
> pywintypes.com_error: (-2147221164, 'Class not registered', None, None)
>
> If I use
> prmidattrs = MyModule.SmRecordList()
What will generally work is to make sure that the class name you are
using is an *interface* (rather than a CoClass), and you can pass an
existing COM object - eg:
ob = win32com.client.Dispatch("whatever")
# Should be early-bound, but it isn't - convert
ob = MyModule._SmRecordList() # the interface, not CoClass
You can use this technique regardless of how you were handed the object.
If you have access to the source of the object or the developers, ask
them to implement the typeinfo classes for their objects (they already
have the type info there, it just isn't exposed via their runtime objects)
Mark.
More information about the Python-list
mailing list