Hello,<div><br></div><div>I am using a call to a windows function via ctypes to retrieve a pointer to the IDispatch interface of an Excel application, something like:</div><blockquote style="margin:0 0 0 40px;border:none;padding:0px">
<div>oledll.oleacc.AccessibleObjectFromWindow(hnd, OBJID_NATIVEOM, byref(automation.IDispatch._iid_), byref(pointer_idispatch))</div></blockquote>where hnd is the window handle to the proper excel window.<div><br><div>In the variable result (with type POINTER(IUnknown)), I have the pointer to the interface.</div>
<div>Currently, to be able to call methods/properties on this COM object, I call the "wrap" function from the comtypes.client library and then use the COM object, something like:</div><blockquote style="margin:0 0 0 40px;border:none;padding:0px">
<div>app = wrap(
pointer_idispatch )</div><div>print <a href="http://app.Application.Name">app.Application.Name</a> '==> "Microsoft Excel"</div><div>app.Application.ActiveWorkbook.ActiveSheet.Cells(1,1).Value[()] = 1</div>
</blockquote><div><br></div><div>However, this is slow (a coupe of seconds to do the wrap) and the resulting object is less friendly to use than the COM object I can get with win32. For instance, i need to use</div></div>
<blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div>app.Application.ActiveWorkbook.ActiveSheet.Cells(1,1).Value[()] = 1</div></blockquote>instead of <br><blockquote style="margin:0 0 0 40px;border:none;padding:0px">
<div>app.Application.ActiveWorkbook.ActiveSheet.Cells(1,1).Value = 1
</div></blockquote><br><div>So my question, how could I instantiate a COM IDispatch object from win32 (equivalent of 'app' hereabove) when I have the pointer to the IDispatch interface ('pointer_idispatch' hereabove) ?</div>
<div><br></div><div>thank you</div><div><br></div><div>Sebastien</div><div><br></div><div><br></div>