SAFEARRAY(ISpecific*)* type in COM Automation from Python
Putland, Karl
KPutland at servicemagic.com
Fri Apr 6 11:41:47 EDT 2001
> -----Original Message-----
> From: Alex Martelli [mailto:aleaxit at yahoo.com]
> Subject: SAFEARRAY(ISpecific*)* type in COM Automation from Python
>
>
> A problem I hadn't seen yet -- wonder if anybody has already
> solved it and can offer advice...
>
> I have to call a method on an Automation object that needs
> a parameter of type SAFEARRAY(IFoo*), where IFoo is a (dual)
> interface defined in that same type library. I can make
> suitable objects that implement IFoo through suitable factory
> methods in that object-model, but when I then try to pass a
> list of those 'suitable objects' where the SAFEARRAY(IFoo*)
> is required, I get a "type mismatch" COM error:
>
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> File
> "d:\python20\win32com\gen_py\F4503A16-F637-11D2-BD55-005004004
> 05Bx0x1x0\I
> ProfileCreator.py", line 31, in AddProfile
> ret = self._oleobj_.InvokeTypes(0x1, LCID, 1, (9, 0),
> ((24585, 1), (11,
> 1)),
> pCvs, autoConstraint)
> pywintypes.com_error: (-2147352571, 'Type mismatch.', None, 1)
>
> Is there some known way to solve this peculiar problem...?
>
>
> Alex
>
>
Bellow is a snipped dredged up from a Python
COM server I wrote a while back. I think
you will find this helpful. First create
a collection, then wrap the collection.
--Karl
def foo:
...
tmpfields=[]
for field in table_inst.fields:
field._public_methods_ = ['read',
'write',
'append']
field._public_attrs_ = ['name',
'size',
'type'
'value']
name = string.lower(field.name)
field = win32com.server.util.wrap(field)
tmpfields.append(field)
setattr(table_inst, name, field)
# turn tmpfields into a collection
if debug:
print "\n turn tmpfields into a collection"
print "\n tmpfields Before: " + `tmpfields`
tmpfields=win32com.server.util.Collection(tmpfields,1)
if debug: print "\ntmpfields After: " + `tmpfields`
### WOW I finally grok
# Wrap the Collection.
tmpfields=win32com.server.util.wrap(tmpfields)
setattr(table_inst, "fields", tmpfields)
# Return a wrapped table
wrappedtable=win32com.server.util.wrap(table_inst)
return wrappedtable
More information about the Python-list
mailing list