Anthony Tuininga schrieb: > > The traceback doesn't produce anything useful, unfortunately. > > Traceback (most recent call last): > File "CreateSchedule.py", line 17, in <module> > modelSpace = app.ActiveDocument.ModelSpace > _ctypes.COMError: (-2147467262, 'No such interface supported', (None, > None, None, 0, None)) > > I've tried and app.ActiveDocument returns something but any attempt to > reference ModelSpace or anything else that looks like an object > doesn't appear to work. > > As for debugging, what sort of debugger were you referring to? I'm not > familiar with the comtypes architecture yet so some pointers as to > where to look would be helpful. I already saw the "QueryInterface" > call but didn't notice anything calling that before the exception took > place. Any suggestions on where to look next would be helpful. Thanks!
I debug with pdb from the command line; other debuggers may work as well. Here is an commented example stepping through app.Documents where app is a com pointer to MS word: C:\sf\comtypes>py25 Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> from comtypes.client import CreateObject >>> word = CreateObject("Word.Application") >>> word.Documents <POINTER(Documents) ptr=0x254c4c at b8ca30> >>> type(word).Documents <property object at 0x030928A0> >>> type(word).Documents.fget <COM method offset 11: WinFunctionType at 0x0304C5D0> >>> type(word).Documents.fget.restype <class 'ctypes.HRESULT'> >>> type(word).Documents.fget.argtypes (<class 'ctypes.LP_POINTER(Documents)'>,) >>> So, 'word.Documents' is a property, and its fget function is a WinFunctionType (a ctypes implemented 'callback' function) that wraps the native COM call. We can call the fget function with the word object to retrieve the 'Documents' attribute; this is what happens internally in Python when 'word.Documents' is evaluated: >>> type(word).Documents.fget(word) <POINTER(Documents) ptr=0x271994 at b8ca30> >>> Now stepping through this with pdb. We cannot step through the actual WinFunctionType call with the Python debugger since this is implemented in C, but we see the processing in Python to retrieve the return value. >>> pdb.run("word.Documents") > <string>(1)<module>() (Pdb) s --Call-- > c:\sf\comtypes\comtypes\client\__init__.py(38)wrap_outparam() -> def wrap_outparam(punk): (Pdb) l 33 import comtypes.gen 34 35 ### for testing 36 ##gen_dir = None 37 38 -> def wrap_outparam(punk): 39 logger.debug("wrap_outparam(%s)", punk) 40 if not punk: 41 return None 42 if punk.__com_interface__ == comtypes.automation.IDispatch: 43 return GetBestInterface(punk) (Pdb) 44 return punk 45 46 def GetBestInterface(punk): 47 """Try to QueryInterface a COM pointer to the 'most useful' 48 interface. 49 50 Get type information for the provided object, either via 51 IDispatch.GetTypeInfo(), or via IProvideClassInfo.GetClassInfo(). 52 Generate a wrapper module for the typelib, and QI for the 53 interface found. 54 """ (Pdb) Now we can single-step through the code in the wrap_outparam() function. Hope that helps, -- Thanks, Thomas ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ _______________________________________________ comtypes-users mailing list comtypes-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/comtypes-users