How do I access COM object's nondefault interface?

Markus Willi nallanews at bluewin.ch
Sat Aug 17 17:00:17 EDT 2002


Josef Sachs wrote:
> Can anyone tell me how to access a COM object's nondefault interface?

I had the same question and after searching the net and watching source 
(win32com/...) i come to this hack:

given:
   class x with default interface X
   class y with default interface Y
   class y implements the interface Z too
   class x has a member (m) wich return a object y through the interface Z

solution:
   # y has now the Z interface
   y = x.m
   # y has now the 677...5A9 interface - Y interface
   y = win32com.client.Dispatch(y, 'm', 
'{677B5E26-A514-11D6-8F69-0048545505A9}', UnicodeToString=0)


I don't know if this hack is usefull for you. But I don't like it, because:
- I need the tool makepy
- the second parameter could be anything, the eg. I found used the name 
of a member function from the class x?!?
- the third parameter should be a name of the form "library.class", 
instead the CLSID

If I use the tool makepy to generate python code for early binding, I 
can not belive why I have to type somthing like this
x = win32com.client.Dispatch("library.class")
instead
x = library.class.
But this is stuff for a new thread.

OK. my english experience are better than python ;) That mean I use 
python just four days now and its great. I hope someone has a better 
solution to change the interface.

Markus




More information about the Python-list mailing list