ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> python-list
python-list
Re: How do I access COM object's nondefault interface?
by Carl Waldbieser other posts by this author
Aug 18 2002 7:29AM messages near this date
Re: How do I access COM object's nondefault interface? | Re: How do I access COM object's nondefault interface?
This technique also has a subtle problem that it doesn't always work-- here
is when and why:

As long as the COM method invocations don't cross apartments, everything
will work fine.  However, when cross-apartment calls are made, the internal
COM library tries to increase throughput by caching info in an entity known
as the "proxy manager".  One of the things the proxy manager happens to do
is cache the *first* IDispatch pointer that has been marshalled from the
object.  That means if the default interface was already passed to the proxy
manager, that is the IDispatch interface it is going to hand out, no matter
what interface x.m in the example below tries to return.

I am also interested in any information concerning how to access COM custom
interfaces from Python.  I've read "Python Programming on Win32", but I
didn't see any examples of how to communicate through an arbitrary interface
using pythoncom (though the chapter on advanced COM seemed to hint that this
was possible).  I would appreciate any URLs to aditional literature on the
subject as my Google searches pretty much tell me that "COM" is a pretty
common world on the Web.

Carl Waldbieser
waldbie@[...].net

"Markus Willi" <nallanews@[...].ch>  wrote in message
news:3D5EB961.3050705@[...]..
>  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
> 


-- 
http://mail.python.org/mailman/listinfo/python-list
Thread:
Josef Sachs
Carl Waldbieser
Josef Sachs
Carl Waldbieser
Markus Willi
Josef Sachs

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved