win32com extension help

Roger Upole rupole at hotmail.com
Sun Oct 17 14:11:36 EDT 2004


"Peter Sparago" <psparago at yahoo.com> wrote in message
news:584da15e.0410170900.3f090aa4 at posting.google.com...
> (Sorry in advance for the long post.)
>
> Hi,
>
> I'm having a great deal of difficulty buiding a Python COM extension.
> I am using the MSHTML ActiveX control in my application but I need to
> interact with and implement some Custom COM interfaces. All is well
> with the basic operation of the control using Python.
>
> Basically, I want to take over the right-click (context) menu from
> MSHTML. To do this (to the best of my knowledge), you must request the
> ICustomDoc interface from the control and set up your own
> implementation of the IDocHostUIHandler interface. In Python COM
> extension lingo, I need an ICustomDoc interface and an
> IDocHOstUIHandler gateway.
>
> First off, any link to HOW-TO documentation on this subject would be
> greatly appreciated.
>
> I wanted to start with something very simple, so I am trying to
> implement an extension that understands only the ICustomDoc interface.
> I ran makegw and hand-edited the resulting interfaces to get my .PYD
> to compile and link (and even load!).
>
> I pretty much understand the actual implementation of the COM support
> generated by makegw, but I'm very hazy on the extension "wiring"
> necessary to publish this COM support to Python. (i.e. the use of
> PyMethodDef and PyCom_InterfaceSupportInfo etc.)
>


Basically, you construct an array of PyCom_InterfaceSupportInfo's
that contain the interfaces your extension module will implement.
(the PYCOM_INTERFACE_ macros require very strict naming conventions)

When you pass this array to PyCom_RegisterExtensionSupport,
it adds your interfaces to Pythoncom's internal array of supported
interfaces.  This is used to lookup the type object that's used as
a constructor for the Python interface object.

> So, I thought I'd look for a working example and do a knock-off. I'm
> running Python 2.3 and I've downloaded and built pywin32-203. I have
> previously worked in great detail with the IFilter interface, so I
> chose that win32comext project to use as a model. The problem is, when
> I run the demo python code (called filterDemo.py) to exercise the
> IFilter support, it fails with the following error:
>
> C:\Joey\pywin32-203\com\win32comext\ifilter\demo>filterDemo.py
> test.txt

Just a guess here, do you have .py files registered to open with a debug
build of python ?  If so, you'll need to have debug versions of all the
extension
modules (*_d.pyd) alongside the normal .pyd files to be able to
import them.  Or vice-versa, if you only have a debug version of the
extension
built you  won't be able to import it from a normal python.exe.

  hth
       Roger





More information about the Python-list mailing list