Two COM Questions: QueryInterface, and Callback Inheritance

Christopher Paulicka cpaulicka at 8cs.com
Tue Jul 25 22:55:15 EDT 2000


 > How to QueryInterface for a new dispatch interface?
>
> You just perform the QI - but on the "_oleobj_" object.  ie:
>
> > >>>    import win32com.client
> > >>>    d = Dispatch("MyCoolThing.App")
> > >>>    s = d.GetOtherThing()
>
> You need to do something like:
> >>> s = d.GetOtherThing()
> >>> other_s = s._oleobj_.QueryInterface("{new_iid}")
> >>> s = Dispatch(other_s) # Turn it back into a useful object.
>

Well, that seems straightforward.  But, I get the following error message:
 >>> other_s = s._oleobj_.QueryInterface("{new_iid}")
TypeError: There is no interface object registered that supports this IID

# If I get the type of s, and try to use it's CLSID, that doesn't work.

>>>  print s
<win32com.gen_py.DirectAnimation Library.IDAGeometry>

>>> other_s =
s._oleobj_.QueryInterface(DirectAnimationModule.IDAGeometry.CLSID)

# Maybe EnsureModule hasn't registered this IID?
# I try manually adding the CLSID directly
>>> other_s =
s._oleobj_.QueryInterface('{EB5093C7-56F9-11D2-88CE-00C04FA35859}')

# That doesn't work either.
# However, if I change the method (from above)
>>>    s = d.GetOtherThing()

# So I rewrote GetOtherThing() directly in the makepy generated file
# and put the ID in place

 def GetOtherThing(self, Duration=defaultNamedNotOptArg):
  ret = self._oleobj_.InvokeTypes(0x60020009, LCID, 1, (9, 0), ((5,
1),),Duration)
  if ret is not None: ret = win32com.client.Dispatch(ret, 'Duration',
'{EB5093C7-56F9-11D2-88CE-00C04FA35859}', UnicodeToString=1)
  return ret

# Now it works fine!
# So, what can I do?  It seems inelegant to have to change all of the
automatically generated # methods, and wrong, since I am upcasting in
effect.






More information about the Python-list mailing list