[Tutor] COM Interfaces

Lloyd Kvam pythontutor@venix.com
Mon, 13 May 2002 09:04:07 -0400


Python depends on the registry entries to find the COM object it is running.
The name passed to Dispatch MUST exactly match the name in the registry.  You
can't make it up.

I suspect that 'MSXML2.DOMDocument30' should be 'MSXML3.DOMDocument30'.  If you
search your registry, you should be able to find the name.

To run your VB COM object, you need to get it registered.  Then simply pass
the name you used to register it to dispatch, just like you did for MSXML.

The Win32 Programming with Python explains this very well.  The VB documentation
should tell you how to register your VB code.

dominic.fox wrote:

> I wonder whether anyone can help with a slightly more advanced Python/COM
> question. I'm being impatient here - as helpfully suggested, I ought to go
> and get Win32 Programming with Python, which no doubt contains the answer to
> this question, but I've just spend thirty-odd quid on an admittedly
> excellent Python book already this month and may have to hang on before I
> can convince my spouse that I can afford another one. If there's a quick
> answer someone can give me off the top of their head, then I'd be most
> grateful for it.
> 
> I've managed to create an MSXML3 DOM and manipulate it in the ways I'm used
> to from VB using win32all's Dispatch('MSXML2.DOMDocument'). This didn't work
> for 'MSXML2.DOMDocument30' for some reason, which may have to do with my
> main question  (the reason I'm using MSXML3, by the way, is that I'm a
> little hazy about the current level of support in Python for XPath and
> XSLT). This is good: it means that I can go into work tomorrow and talk
> about how I might like to start using Python quite soon to do some of the
> things we currently do in VB, and if they say "but what about XML / IE
> Explorer automation / Attachmate 3270 SNA Client automation / etc." I can
> say, "Oh, Python will do that too" with a reasonable amount of confidence.
> That doesn't mean they'll let me use it, of course, but it might be a start.
> 
> A fairly common practice in writing VB code is to write a class which
> "implements" the COM interface of another. This is about as good as it gets
> in VB from an OO point of view; it means that you can create a number of
> classes which share the same methods, properties and functions, and pass
> instances of them interchangeably to client code. The trouble is that I
> can't see how to access the implemented attributes of these dual (or
> possibly multiple) interface classes using win32all's Dispatch. In VB you'd
> say something like:
> 
> Dim GenericFoo as IFoo
> Set GenericFoo = New ActualFoo1    ' ActualFoo1 "implements" IFoo, which has
> a property Bar()
> Msgbox GenericFoo.Bar()
> Set GenericFoo = New ActualFoo2    ' ActualFoo2 also implements IFoo
> Msgbox GenericFoo.Bar()
> 
> Now, assuming I had some VB classes IFoo, ActualFoo1 and ActualFoo2 which
> actually did something useful, and I wanted to use them in Python. How would
> I go about creating, and calling Bar() on, an instance of one of these
> classes?
> 
> thanks for any help,
> Dominic
> 
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 
> 


-- 
Lloyd Kvam
Venix Corp.
1 Court Street, Suite 378
Lebanon, NH 03766-1358

voice: 
603-443-6155
fax: 
801-459-9582