I don't seem to be able to connect to a running instance of Word. I get the following error :
Traceback (most recent call last): File "c:\Python24\Lib\site-packages\pyHook\HookManager.py", line 325, in MouseSwitch return func(event) File "D:\DAProject\Workspace\context\inputhook\RDFIO.py", line 122, in onMouseEvent self.whatAmIDoin(event) File "D:\DAProject\Workspace\context\inputhook\RDFIO.py", line 130, in whatAmIDoin l_appName = self.getCurrentApplication() File "D:\DAProject\Workspace\context\inputhook\RDFIO.py", line 62, in getCurrentApplication self.wordInfo() File "D:\DAProject\Workspace\context\inputhook\RDFIO.py", line 81, in wordInfo l_wobj = win32com.client.Dispatch("Word.Application") File "c:\Python24\Lib\site-packages\win32com\client\__init__.py", line 95, in Dispatch dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx) File "c:\Python24\Lib\site-packages\win32com\client\dynamic.py", line 98, in _GetGoodDispatchAndUserName return (_GetGoodDispatch(IDispatch, clsctx), userName) File "c:\Python24\Lib\site-packages\win32com\client\dynamic.py", line 78, in _GetGoodDispatch IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.IID_IDispatch) pywintypes.com_error: (-2147417843, 'An outgoing call cannot be made since the application is dispatching an input-synchronous call.', None, None) Thanks a million, Radu. ----- Original Message ---- From: Tim Roberts <[EMAIL PROTECTED]> To: Python-Win32 List <python-win32@python.org> Sent: Friday, 24 August, 2007 11:04:02 PM Subject: Re: [python-win32] get running application handle Radu Ciora wrote: > Is it possible to get a handle to a running application like the one I get > when I explicitly start an application myself using the > win32com.client.Dispatch("Object.Name")? > > Is the one retrieved by win32gui.GetForegroundWindow() the same as the one > above or not, if not how can I get the handle to a running application object. > > I hope I made myself understand. > Well, you are confusing several very different constructs there. What you get back from win32com.client.Dispatch is not a handle at all; it is a pointer to a COM object. It contains methods and properties that you can call directly. What you get back from win32gui.GetForegroundWindow is just a window handle. You can send window messages to it, but there is nothing there to call, and there is no connection to any COM objects. In fact, there is no guarantee that the foreground application offers any COM services at all. Having said that, I assume that what you really want to do, for example, is to connect to a currently running instance of Word. Is that right? Somewhat surprisingly, this depends on the application. For the Office products, if you do a Dispatch on Word.Application while Word is running, you should get a pointer to the existing Word application, and should be able to manipulate the existing documents. For other applications, the answer is "it depends". -- Tim Roberts, [EMAIL PROTECTED] Providenza & Boekelheide, Inc. _______________________________________________ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32 ___________________________________________________________ Yahoo! Answers - Got a question? Someone out there knows the answer. Try it now. http://uk.answers.yahoo.com/ _______________________________________________ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32