On Fri, 13 Jun 2008, Michael Ellery wrote: > Jan Dubois wrote: > > In general it would be better to provide a GUI for your input, using > > Tk, Tkx, Win32::GUI, wxPerl etc. which would avoid the problem > > altogether. > > It's been a long time since I've tried any GUI programming in perl, > but IIRC usually there is a point where you have to call a message > loop in order to allow the UI to process messages. How would that work > with with Win32::OLE's MessageLoop()? Obviously I can't have two > message loops going - would the UI message loop be sufficient to > deliver my COM events (in other words, I'd never have to call OLE's > MessageLoop)?
There isn't really anything OLE specific about Win32::OLE::MessageLoop(). It does exactly the same thing as a GUI messageloop: it receives messages from the Windows message queue and dispatches them to the destination window. If you have a GUI, then you never need to worry about the message loop for dispatching OLE events; it will work automatically. The reason you only need to worry about the messageloop for OLE events is that all other OLE functionality (method calls, property setting and getting) will implicitly spin the message loop for you. This is part of OLE itself, not the Win32::OLE module. For example, when you invoke an Excel method from Perl, what really happens is that OLE sends a Windows message to Excel, asking it to perform this method call and then send the result back to Perl. In order to receive the result OLE has to process the message loop until the result message from Excel arrives. Any event notifications generated by the method call will also be dispatched automatically during this wait. Once the method result arrives OLE will then pass the result back to Win32::OLE which will repackage it as a Perl value. As you can see, OLE can only process incoming messages while it is waiting for one of its calls to return. If you want to receive OLE events asynchronously then you have to run a message loop yourself while you are waiting for something to happen. A GUI application does exactly the same: it is just waiting for messages to arrive to process them. And you are not supposed to do any blocking I/O in your message callbacks because it would stop the processing of any further incoming messages until you unblock. Cheers, -Jan _______________________________________________ Perl-Win32-Users mailing list [email protected] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
