Events in win32com

Alex Martelli aleaxit at yahoo.com
Tue Dec 19 20:49:13 CET 2000


"Paul Moore" <paul.moore at uk.origin-it.com> wrote in message
news:FY0=OlZFLy71DtnK62u5TEPlhOts at 4ax.com...
> On Tue, 19 Dec 2000 13:49:23 +0100, Paul Moore
> <paul.moore at uk.origin-it.com> wrote:
>
> >If I create an object using
> >
> >obj = win32com.client.Dispatch(progid)
> >
> >can I see events from the object?
>
> After scanning Deja, I found an article describing DispatchWithEvents.
> The example in the documentation (OnVisible) works fine. But the
> OnQuit event doesn't seem to work :-( Basically, the event routine is
> never fired. Is this because the event routine has a ByRef "Cancel"
> parameter? Or is it something else?

If the event expects to call a method with one parameter (as it
will, if it's [in,out]; but not if it's just [out] -- this is a key COM
level distinction, but VB tends to the former, not supporting the
latter...) then it will silently fail to call a method that takes no
parameters even if the names coincide.  (Make sure to return the
value you receive as input as your result, to get [in,out] effects).

Also, you need (in general) for makepy to have been run on that
type library, or something equivalent that has processed the tlib
for Python used and placed it in the cache directory of known
type libraryes (the, I believe, EnsureDispatch method of the
gencache module, for example).  Python has to guess if it does
not know the specifics of the type library (just as VB would have
to guess in the same case) and it won't always guess right!-)


Alex






More information about the Python-list mailing list