Problem with pywintypes.Time
Dave Foster
dave at dvdfoz.eclipse.co.uk
Tue Jun 3 08:18:37 EDT 2003
I am having problems calling a COM method which takes a DATE type as
an argument. I cannot seem to directly construct a pywintypes.Time
instance and pass as an argument.
To illustrate, I created a DLL server, build on VC++ 6 using the ATL
wizard, and added a couple of simple methods, which just return their
arguments.
---------------------------------------------
STDMETHODIMP CPyDateTest::Test1(long code, DATE *date)
{
*date = (DATE)code;
return S_OK;
}
STDMETHODIMP CPyDateTest::Test2(DATE date, long *code)
{
*code = (long)date;
return S_OK;
}
constructed the COM wrapper using makepy, and I have a test script
--------------------------------
import win32com.client
import pywintypes
import time
dateProblem = win32com.client.Dispatch('PyDateProblem.PyDateTest')
date = dateProblem.Test1(30000) # construct date via server
print 'Server constructed Date -----', date
code = dateProblem.Test2(date) # this works fine
print 'COM Date code -----', code
date2 = pywintypes.Time(time.time()) # directly construct date
print 'Directly constructed date -----', date2
code2 = dateProblem.Test2(date2) # this raises SystemError
print 'Do NOT See this', code2
---------------------------------
when I run this, Python 2.2.2, the date returned from call to the
Test1 method works fine, the directly constructed date raises a
SystemError.
The output I see is,
-----------------------------------------
Server constructed Date ----- <PyTime:18/02/1982 00:00:00>
COM Date code ----- 30000
Directly constructed date ----- <PyTime:03/06/2003 13:14:34>
Traceback (most recent call last):
File "testScript.py", line 14, in ?
code2 = dateProblem.Test2(date2) # this raises SystemError
File "C:\Python22\Lib\site-packages\win32com\gen_py\F869A325-F3EE-4E60-957F-37
B9BD15E622x0x1x0.py", line 34, in Test2
return self._ApplyTypes_(0x2, 1, (24, 0), ((7, 1), (16387, 2)),
'Test2', Non
e,date, code)
File "C:\Python22\Lib\site-packages\win32com\client\__init__.py",
line 341, in
_ApplyTypes_
return self._get_good_object_(apply(self._oleobj_.InvokeTypes,
(dispid, 0, w
Flags, retType, argTypes) + args), user, resultCLSID)
SystemError: NULL result without error in PyObject_Call
-----------------------------------------------------
Thanking all in advance for any advice or tips on what I am doing
wrong.
Dave Foster
More information about the Python-list
mailing list