[python-win32] Casting to interface from different typelib?

Mark Hammond skippy.hammond at gmail.com
Sun Jan 11 23:27:57 CET 2009


On 11/01/2009 5:34 PM, Ben Gordon wrote:
> Mark,
>
> MH> pB = mod.InterfaceB(pA.QueryInterface(IID_B, pythoncom.IID_IDispatch))
>
> Thanks so much for the suggestion. I tried it, but it appears that pA
> does not provide a QueryInterface method.

oops - try pA._oleobj_.QueryInterface(...)

> I'm not sure what magic is involved behind the scenes, but this type of
> cast seems to be comparatively convenient and nearly transparent in
> VBA/VB (VB requires an explicit CType call), without the need to lookup
> CLSIDs/IIDs.

Yeah - its a little tricky to make it seamless in Python, but the code 
to CastTo isn't *that* long or hairy, so it should be possible to see 
what is happening and why.

Cheers,

Mark


More information about the python-win32 mailing list