comtypes
comtypes copied to clipboard
PumpEvents - does not work on windows 10
Using python 3.9.7 and Windows 10.
When trying out a COM DLL that supports events (written in C++) the ShowEvents function detects and prints out the events correctly but attaching an event handler and using PumpEvents(1) does not result in any report.
However same script reports events when I replace "PumpEvents(1)" with "pythoncom.PumpMessages()".
Any idea why i need to pump messages using another python module?
Hi @QuadCorei8085, I have the same Python 3.9.7, Win 10 and using a COM DLL written in C++ that fires events, and I have had no problems with PumpEvents(). Note that you don't need a separate event handler if using ShowEvents(), it will print the event calls itself (I don't know if having a second handler interferes with that in some way). Are you keeping open the connection returned by ShowEvents()? Perhaps share the script (or the minimum example code) and we can try and figure out if there is anything wrong with it. My code looks like this:
import comtypes.client
obj = comtypes.client.CreateObject("MyLibrary.Object")
conn = comtypes.client.ShowEvents(obj)
obj.generate_event()
comtypes.client.PumpEvents(1)
where MyLibrary.Object raises an event in response to the generate_event() method being called. This generates output like:
# event found: IMyObject_MyEvent
Event IMyObject_MyEvent(None)