[python-win32] "Casting" COM objects

Jens B. Jorgensen jens.jorgensen@tallan.com
Thu, 03 Apr 2003 17:14:32 -0600


Paul Prescod wrote:

> Jens B. Jorgensen wrote:
>
>> ...
>>
>> It is inconvenient, I know. It is no wonder more recent models such 
>> as Java and CLR support a "reflection" interface to discover type 
>> information about an object pointer eh?
>
>
> I didn't know that COM lacked that. Thanks for the info.

>
>
> Still, there is at least enough reflection in there to support 
> dispatch interfaces. 

Even this is not strictly true. The only type information is known from 
the type library. The dispatch interface literally let's you try to 
lookup a method or propery by name. If it isn't there then you don't get 
anything. It won't give you a list of things that you can call, it just 
let's you try to look something by its name. The type library enumerates 
what methods and "properties" (these are really methods too by the way) 
are supported by the object.

> Would it be feasible for the classes generated by MakePy to "try" a 
> method call or property assignment even if it wasn't known at compile 
> time? Is the underlying object used in a dynamic dispatch interface 
> versus a Makepy interface basically the same object? If so, the Makepy 
> classes could try the dynamic approach before giving up and throwing 
> an exception... 

If you used the dispatch methods directly to try to lookup the 
method/property name then you can indeed do this. I have never tried 
this myself. I wouldn't think it would be all that hard to arrange for 
the makepy-generated code to attempt to lookup names that it doesn't 
already have.

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

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