[python-win32] COM array problem
Reinier Heeres
reinier at heeres.eu
Thu Jul 30 15:13:49 CEST 2009
Hi Mark,
Thanks for your quick reply.
On Wed, Jul 29, 2009 at 6:49 AM, Mark Hammond<skippy.hammond at gmail.com> wrote:
> On 29/07/2009 4:29 AM, Reinier Heeres wrote:
>>
>> Hi everybody,
>>
>> I have a problem with a function of a COM object that is supposed to
>> return an array of data. The function prototype generated by
>> win32com's EnsureDispatch is as follows:
>>
>> def GetFrame(self, frame=defaultNamedNotOptArg,
>> FrameVariant=defaultNamedNotOptArg):
>> """Get Frame Data"""
>> return self._ApplyTypes_(10, 1, (24, 0), ((2, 1), (16396, 3)),
>
> This is declaring the function has a return type of 24 (VT_VOID), and takes
> 2 params - one in param of type 2 (VT_I2) and the other a 'retval' param of
> 16396 == 0x400c == VT_BYREF | VT_VARIANT.
>
>> u'GetFrame', None,frame
>> , FrameVariant)
>>
>> which from my understanding means that the type which gives the
>> problem is VT_R4 | VT_BSTR | VT_BYREF. (I've seen problems with byref
>> return values before on the mailing list archives, but I don't know if
>> they apply here).
>>
>> The error is slightly undescriptive (snipped a part):
>>
>> 454 def _ApplyTypes_(self, dispid, wFlags, retType,
>> argTypes, user, resultCLSID, *args):
>> 455 return self._get_good_object_(
>> --> 456 self._oleobj_.InvokeTypes(dispid, 0,
>> wFlags, retType, argTypes, *args),
>> 457 user, resultCLSID)
>> 458
>>
>> com_error: (-2147352567, 'Exception occurred.', (0, None, None, None,
>> 0, -2147024809), None)
>>
>> I don't exactly understand where the problem is: is it before the call
>> to the actual COM function while creating an empty object, in the COM
>> call, or after the call casting the result? Any ideas on how to fix
>> this would be welcome; I could try to make patches for win32com.
>
> The problem is the COM object returning DISP_E_EXCEPTION with an scode value
> of -2147024809 - which in turn is E_INVALIDARG.
>
>> BTW: I can get it to work with comtypes (but that gives problems on
>> some other calls), so in principle it should be possible.
>> Unfortunately I don't have access to the source of the COM object I'm
>> using.
>
> I suspect pythoncom is passing the variants described above - but maybe the
> variant isn't initialized as expected or something. Do you know exactly how
> the variants passed by ctypes were laid out?
comtypes generates the following python code to create the function:
COMMETHOD([dispid(10), helpstring(u'Get Frame Data')], HRESULT, 'GetFrame',
( ['in'], c_short, 'frame' ),
( ['in', 'out'], POINTER(VARIANT), 'FrameVariant' )),
I'm not sure how exactly it calls the method though (the code is not
easy to debug if you're unfamiliar with!).
In the win32com generated python code I tried all 3 candidates I could
give: pythoncom.Missing, .Empty and .ArgNotFound to initialize the
empty parameters.
Does this help or should I try to dig deeper?
> Cheers,
> Mark
Regards,
--
Reinier Heeres
Tel: +31 6 10852639
More information about the python-win32
mailing list