How do I access COM object's nondefault interface?

Carl Waldbieser waldbie at
Sun Aug 18 21:09:52 EDT 2002

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 at

"Josef Sachs" <sachs at> wrote in message
news:o9ptwgmj7z.fsf at
> >>>>> 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
> In particular, see:
> <URL:$u1f$>
> <URL:
> <URL:$4p3.101235@news-server>
> 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.

More information about the Python-list mailing list