Christian K. schrieb:
> 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.

I will try to find this problem later.

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

pywin32 uses the IDispatch interface, which probably returns the time in a 
VARIANT with
typecode VT_DATE, and of type C double.  This way the code knows that a 
date/time is meant
and can convert accordingly.

The outlook type library seems to use the C double also, but comtypes does not 
know that
a date/time is meant.  In COM, date/time is represented as double, in days 
since 30. Dec 1899.
In comtypes\automation is code to do the conversion from/to VARIANT instances, 
from what I see
there you should be able to do the conversion yourself with code like this:

import datetime
_com_null_date = datetime.datetime(1899, 12, 30, 0, 0, 0)

def double_to_datetime(days):
    "Takes a COM date/time value, a float, and returns a datetime object"
    return datetime.timedelta(days=days) + _com_null_date

Thomas

_______________________________________________
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32

Reply via email to