How to use the callback of COM objects

Dale Strickland-Clark dale at
Wed Oct 3 16:59:51 CEST 2001

"Gillou" <nospam at> wrote:

>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 "", line 7, in ?
>    ox.onreadystatechange = HandleReadyState
>  File "C:\Python21\win32com\client\", line 467, in __setattr__
>    self._oleobj_.Invoke(self._olerepr_.propMapPut[attr].dispid, 0,
>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.

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