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

Christian K. ckkart at hoc.net
Fri Apr 20 09:09:17 CEST 2007


Thomas Heller wrote:
> 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.

I had the comtypes directory removed before installing from svn.

> 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.

Well, here it doesn't.

> 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)

Ok, I've no idea what the 'interface' is in this case. Time for a good 
book obviously.

>> 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.

The point why I was asking that, is, that in order to circumvent some 
silly Outlook security barrier when accessing it with simple mapi one 
has to use the extended mapi interface according to what I've understood 
from googeling. pywin32 ships with an example of how to create a new 
mail using the extended mapi and I guess this is the way to go for me.

But honestly I still know too few to even use all those acronyms properly :)

> 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.

Thank you for pointing that out.

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

I successfully read out the Outlook inbox using comtpyes but finally 
switched back to pywin32 because I was not able to interprete the value 
of MailItem.CreationTime,
e.g:
obj.Session.Folders['mail.server.com'].Folders['INBOX'].Items.Item(1).CreationTime
which looks like a posix timestamp which dates back to the 70th. I guess 
pywin32 is doing some conversion there and comtypes is not?

Anyway I'll have a look at both again after having read some more 
documentation.

Christian



More information about the Python-win32 mailing list