[python-win32] com events while running wx main loop

Thomas Heller theller at ctypes.org
Thu Apr 19 21:02:22 CEST 2007


Christian K. schrieb:
> 
> Now I installed comtypes from svn and get this error running your new
> example:
> 
> Traceback (most recent call last):
>    File "C:\Dokumente und Einstellungen\ck\Desktop\x.py", line 64, in ?
>      Listener()
>    File "C:\Dokumente und Einstellungen\ck\Desktop\x.py", line 50, in 
> __init__
>      self.com_init()
>    File "C:\Dokumente und Einstellungen\ck\Desktop\x.py", line 59, in 
> com_init
>      self.s = comtypes.client.GetEvents(self.o, sink)
>    File "c:\Python24\Lib\site-packages\comtypes\client\__init__.py", 
> line 358, in GetEvents
>      raise TypeError("cannot determine source interface")
> TypeError: cannot determine source interface

First of all, when you install a new comtypes version you should clear the
contents of the comtypes\gen directory, so that the typelib wrappers can
be regenerated.  The old versions from previous comtypes releases should
better not be used.

Second, if you are running the exact sample that I posted then it should work
for InternetExplorer, and with slight changes also for Outlook.  At least
it worked for me.

Third, the GetEvents function requires that the COM object exposes type information,
and that this information includes info about the outgoing default interface.
Some objects do not do this, then you have to find the outgoing interface yourself
and pass that as the 'interface=...' parameter to the GetEvents function (this description
is from memory, read the sources to find out).

> As I'm real beginner with python on windows I'd like to ask some 
> elementary questions if you don't mind:
> 1) Does comtypes depend on pywin32?

No, it is completely independend.

> 2) It seems that it provides the same (similar) mapi interface as 
> pywin32, so can it be used as a replacement for pywin32?
> 3) Does comtypes expose the extended mapi?

I never used mapi so I cannot really answer this.
comtypes normally creates the typelib wrappers itself; when these
contain the mapi interfaces then there are chances that it would work.

> Thanks for your help, Christian

If you are a newbie to COM, and pywin32 exposes the functionality that you need
you should probably better use pywin32. It is stable, well maintained, and documented.
You should probably get the 'Python Programming on Win32' book, or at least read
the online sample chapter.

However, if you are brave, if you need to use non-dispatch based interfaces; then
comtypes may be what you want.

Hope it really helps,

Thomas



More information about the Python-win32 mailing list