[python-win32] Re: Can we add 'native COM support' to a 3rd party DLL/OLB

Craig Taverner craig.taverner at comopt.com
Fri May 23 15:45:34 EDT 2003


> I have not really followed the discussion, but ctypes has support
> for vtable based interfaces. I'm currently writing some docs, you may
> want to check it out:
> 
> http://starship.python.net/crew/theller/ctypes/
> http://starship.python.net/crew/theller/ctypes/com.html
> http://starship.python.net/crew/theller/ctypes/sum_sample.html
> 
> > > While comfortable with C, C++ is something I've never gotten into.
I
> > > was hoping I could use Python instead of VB for my Arc based app.
> 
> To use ctypes beyond very basic use, you certainly need C knowledge.

Thanks Thomas,

A quick read of the com.html and sum_sample.html is very interesting.
I'm currently having trouble sending events from pythoncom servers to VB
clients. Do you think the ctypes module will work better for me in this
regard. The only reference to events that I found in your docs was the
ctypes.com.connectionpoints module, which you say is for receiving
events.

Actually my problem involves a design that I'm sure is not uncommon, and
I expect either PythonCOM or ctypes can solve it, but I've just not
figured out how. If you have any advice, I'd love to hear it. The
problem is I have a VB client (so single threaded apartment), and some
multithreaded python code that does a bunch of calculations, some of
which are time consuming. I want to glue the two together with COM such
that:
- VB CoCreates a python COM object which it calls to start the
calculation
- python creates a second thread to do the calculation, so the
'StartCalcultion' is non-blocking.
- python thread signals the VB when it's finished (I've tried a callback
VB COM object, which sort of works, and then crashes after # calls, but
would probably prefer to use windows messages or some kind of events).

Having just read the threads chapter of 'Inside COM', I'm half confident
I know what kind of threading models to use, but my first attempt with
PythonCOM generated OLE errors on the
'CoMarshalInterThreadInterfaceInStream' call to pass the callback VB
object to the new thread. Everything I've read seemed to indicate that I
needed that call, but things work better without it.

However, if I knew how to work events, I would not have to worry about
passing VB COM objects between threads. I've only found how to handle
events in python, not how to fire them. Any ideas?

Thanks, Craig




More information about the Python-win32 mailing list