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 19 2002 1:09AM messages near this date
How do I access COM object's nondefault interface? | Re: How do I access COM object's nondefault interface?
Thanks for the info.

I am just starting to learn Python, so attacking the problem from the Python
side of things is still tough for me.  However, from the COM side of things,
the answer is not too hard.  Say you have object "a" which has a default
interface "A" and another interface, "X" (which is derived from IDispatch).
If you would like to access the X interface from Python, you can simply
create another COM object, "b" that has "X" as its default interface.  This
is pretty trivial to do using VC++ and ATL, but it can be very tedious if
interface "X" is very large.  Internally, "b" has a member object "a" to
which it delegates all its method invocations.  From Python, you just create
a "b" whenever you need an "a".

Of course there are problems with this technique.  If you do not create the
object directly (like getting an ADODB.Field object from an
ADODB.Recordset), the object will obviously not be wrapped in your proxy
object.  Also, it tends to be difficult to switch between the interfaces.
That would require further messy work.  There are a number of stratagems I
can think of, all of them which seem pretty awful.

#1) Object "b" supports a custom interface "Y" that accesses its internal
member, "a".  A third object, "c", has an interface, "C" with two methods:
C.getAfromB(b) takes the proxy object "b", internally uses its "Y" interface
to get a reference to "a", and returns it.
C.getBfromA(a) takes an object "a", creates a wrapper, "b", and uses b.Y to
insert "a" into "b" and returns "b".

#2) Object "b" has interface "A2" which is derived from interface "A", and
it has methods for returning the various interfaces.

Python can therefore get a hold of the various interfaces it needs, but the
solution needs to be tailored to specific interfaces using COM tools rather
than Python tools (and COM tools are not nearly as nice as Python).

There are also subtle problems using proxy objects in this fashion-- you can
ruin performance if one of the objects uses custom marshalling and you don't
take that into account.  If the object has a clone()-style method, it can
escape its wrapper if you are not careful, etc.

Well, that's my 2 cents, for what its worth.

Carl Waldbieser
waldbie@[...].net

"Josef Sachs" <sachs@[...].com>  wrote in message
news:o9ptwgmj7z.fsf@[...]..
>  >>>>> On Sun, 18 Aug 2002 00:29:00 -0700, Carl Waldbieser said:
> 
>  > 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.
> 
>  In general, I would suggest narrowing your search to comp.lang.python
>  and the search page at www.python.org.
> 
>  In particular, see:
>  <URL:
http://groups.google.com/groups?as_umsgid=7sbhuv$u1f$1@[...].com> 
>  <URL:
http://groups.google.com/groups?as_umsgid=36fe8305.1539658@[...].ne
t> 
>  <URL:
http://groups.google.com/groups?as_umsgid=IELf5.12977$4p3.101235@news-server
.bigpond.net.au> 
> 
>  However, as I previously mentioned, I tried the suggested methodologies
>  without success.
> 
>  It would be great if someone could come up with a solution for this,
>  as it appears to be a fairly common problem.


-- 
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