[python-win32] QueryInterface woes

Jens B. Jorgensen jens.jorgensen@tallan.com
Tue, 11 Feb 2003 16:59:15 -0600


In order to access interfaces other than default what you need to do is 
first generate wrapper classes from the type library. This is easily 
done through the makepy.py script included with win32all. Let's say your 
wrapper module is called "Domino" and the object you have is called 
an_item. All you need to do is:

rti = Domino.IRichTextItem(an_item)
rti.SomeMethodYouCouldNotCallBefore()

The makepy.py will make a wrapper class for each interface defined in 
the typelib you point it to. When you pass the object to the constructor 
for this iterface-wrapping-class it will automatically do the 
QueryInterface call for you and give you back the wrapped class you want 
and deserve.

Steven Scott wrote:

>I'm connecting to Domino through it's COM interface with PythonCOM, and I've
>been able to do everything I need to until now.
>I have a method which returns an object of type IItem.  Well, the Domino COM
>interface has this method.  IItem has a "subclass" (I'm not up on all the
>fancy COM terminology) called IRichTextItem.  I need to take the result of
>this method, which is an IItem, and call methods on it which only exist in
>IRichTextItem (yes, it is really an IRichTextItem).  anyway, the COM people
>around here say that I need to use QueryInterface to get the richtext
>interface as opposed to just the regular item.
>
>How do I go about this?
>
>So far I've tried messing around with my object, and calling
>
> body._oleobj_.QueryInterface()
>
>with different stuff.  Pretty much anything I put in resulted with some
>error about it not being able to find that IID, or something.  I went into
>the gen_py directory and got the Domino file, and tried QI() with the
>IRichTextItem CLSID (in the form '{29131574-2EED-1069-BF5D-00DD011186B7}')
>and in this case I get the error "There is no interface object registered
>that supports this IID".
>
>anyway I'm really at a loss, any help would be appreciated.
>
>  
>

-- 
Jens B. Jorgensen
jens.jorgensen@tallan.com

"With a focused commitment to our clients and our people, we deliver value through customized technology solutions"