Hi Mark, On Apr 16, 3:16 am, Mark Hammond <skippy.hamm...@gmail.com> wrote: > On 16/04/2010 7:15 AM,gelonidawrote: > > The model used by pywin32 is more "low level" than that exposed by some > of the MS languages. You probably need something closer to: > > class MgrHandlerClass: > def OnEvent(self, EventID=defaultNamedNotOptArg, ...): > print "Called back with ..." > > manager = win32com.client.DispatchWithEvents("WIA.DeviceManager", > MgrHandlerClass) > manager.RegisterEvent(EventID=constants.wiaEventDeviceConnected,DeviceID=u'*') > manager.RegisterEvent(EventID=constants.wiaEventDeviceDisconnected,DeviceID=u'*') > > And magically your OnEvent should be called when the event happens. > Googling for 'DispatchWithEvents' might find some good hits for more > information. >
I'm still stuck. Please look at following code snippet. I tried to reduce it to the absolute minimum. running under WinXP and python 2.6.4 import win32com.client,pythoncom,time defaultNamedNotOptArg=pythoncom.Empty wiaEventDeviceConnected =u'{A28BBADE-64B6-11D2- A231-00C04FA31809}' # from enum EventID class MgrHandlerClass: # doesn't work either def OnEvent(self, EventID=defaultNamedNotOptArg, DeviceID=defaultNamedNotOptArg, ItemID=defaultNamedNotOptArg): print "Called back with ..." manager = win32com.client.DispatchWithEvents("WIA.DeviceManager", MgrHandlerClass) manager.RegisterEvent(EventID=wiaEventDeviceConnected,DeviceID=u'*') while True: print "sleep" time.sleep(10) When I plug / unplug a USB WIA device nothing shows up. My C# implementation prints messages on wiaEventDeviceConnected / wiaEventDeviceDisconnected events if I register them. What am I missing? Should MgrHandlerClass inherit from some kind of default class? -- http://mail.python.org/mailman/listinfo/python-list