Two COM Questions: QueryInterface, and Callback Inheritance

Christopher Paulicka cpaulicka at 8cs.com
Wed Jul 26 15:07:00 EDT 2000


>
> So maybe I've not understood what is it that you're trying to do.  If
> you want to access another interface of an object you already have
> a reference to, then QI is correct, but you have to specify the interface
> identification -- the IID, not the CLSID.  If you want to instantiate a
> brand-new object, then the CLSID is correct.  But that is a
> substantially different task.
>

Okay, I didn't give enough detail, and I appreciate all your help.

In PythonWin (or pythoncom), when you generate Python wrappers for your
classes, it does so for both the interfaces (dispatch interfaces) and the
coclasses.

If you look at the generated code, it calls their GUID (either CLSID or IID)
the "CLSID" attribute of the particular Python class.

Okay, perhaps the simplest thing to do is to just give you an example, and
see if you can help me.

The following code is exactly what I want to do.  You must have
DirectAnimation installed on your machine (by default with 98, and W2K, also
comes with IE5).

Using makepy, convert "DirectAnimation Library (1.0)".

PythonWin 1.5.2 (#0, May 29 2000, 13:52:29) [MSC 32 bit (Intel)] on win32
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
Portions Copyright 1994-2000 Mark Hammond (MHammond at skippinet.com.au)
>>> import win32com.client
>>> control =
win32com.client.Dispatch("DirectAnimation.DirectAnimationWindowedIntegratedM
ediaControl.1")
>>> m = control.MeterLibrary
>>> print m
<win32com.gen_py.DirectAnimation Library.IDA3Statics>
>>> geo = m.ImportGeometry (r"D:\Program Files\Microsoft SDK for Java
4.0\Samples\DirectX\d3drmviewer\Teapot.x")
>>> geo
<win32com.gen_py.DirectAnimation Library.IDA3Geometry>
>>> geo = geo.Transform(m.Translate3(1.0, 1.0, 1.0))
>>> geo
<win32com.gen_py.DirectAnimation Library.IDAGeometry>

#    Now, I assumed that this was old leftovers, that this IDAGeometry also
supports the IDA3Geometry interface

>>> geo._oleobj_
<PyIDispatch at 0x1232344 with obj at 0x1192464>

>>> qi =
geo._oleobj_.QueryInterface('{EB5093C7-56F9-11D2-88CE-00C04FA35859}')
#IDA3Geometry interface IID
Traceback (innermost last):
  File "<interactive input>", line 1, in ?
TypeError: There is no interface object registered that supports this IID

#    But then I thought, maybe not.  Maybe the old library code doesn't
really make everything as IDA3Geometry interface
#    Well, I can still test QueryInterface(), though

>>> geo2 = m.ImportGeometry (r"D:\Program Files\Microsoft SDK for Java
4.0\Samples\DirectX\d3drmviewer\Teapot.x")
>>> geo2
<win32com.gen_py.DirectAnimation Library.IDA3Geometry>
>>> qi =
geo2._oleobj_.QueryInterface('{C46C1BDF-3C52-11D0-9200-848C1D000000}') #
IDAGeometry Interface IID
Traceback (innermost last):
  File "<interactive input>", line 1, in ?
TypeError: There is no interface object registered that supports this IID

# Now this is really strange, anything supporting IDA3Geometry should be
queryable to IDAGeometry
# Wait, let's try something else...

>>> qi =
geo2._oleobj_.QueryInterface('{EB5093C7-56F9-11D2-88CE-00C04FA35859}')
#IDA3Geometry interface IID
Traceback (innermost last):
  File "<interactive input>", line 1, in ?
TypeError: There is no interface object registered that supports this IID
>>>

# Well, isn't that wierd.  An object of type IDA3Geometry doesn't support
the interface IID for IDA3Geometry?
#
# I am very, very confused.

This leads me to believe that QueryInterface() is not working, or
DirectAnimation is very messed up.





More information about the Python-list mailing list