How to use the callback of COM objects

Dale Strickland-Clark dale at riverhall.NOSPAMco.uk
Wed Oct 3 10:59:51 EDT 2001


"Gillou" <nospam at bigfoot.com> wrote:

>Hi,
>
>I've tried this to provide a callback function to a COM object:
>==============
>import win32com.client
>def HandleReadyState():
>    # anything you want
>    return
>ox = win32com.client.Dispatch('MSXML.DomDocument')
>ox.onreadystatechange = HandleReadyState
>==============
>And the last line raises this:
>==============
>Traceback (most recent call last):
>  File "validation.py", line 7, in ?
>    ox.onreadystatechange = HandleReadyState
>  File "C:\Python21\win32com\client\dynamic.py", line 467, in __setattr__
>    self._oleobj_.Invoke(self._olerepr_.propMapPut[attr].dispid, 0,
>pythoncom.DI
>SPATCH_PROPERTYPUT, 0, value)
>TypeError: Objects of type 'function' can not be converted to a COM VARIANT
>=============
>
>This works perfectly when the equivalent is programmed in javascript.
>"onreadystatechange" is an event that can be handled by a user function.
>
>Did I miss something ?
>
>Thanks in advance fo any hint.
>
>--Gilles
>
>

There is DispatchWithEvents which might be what you're looking for but
I've never tried to use it.
--
Dale Strickland-Clark
Riverhall Systems Ltd



More information about the Python-list mailing list