[python-win32] BSTR

Mark Hammond mhammond at skippinet.com.au
Mon Apr 17 14:13:46 CEST 2006


> I want to share a reply from the developer of MaxIm DL.
> He installed Python2.4.3 and PythonWin build 208,
> just to be able to reproduce this error and it looks to me
> as if the bug could be inside PythonWin.

Please forward this to him.

> I expect Mark Hammond is far too busy to investigate, but if he shows any
> interest at all, tell him he can download a 30-day trial of MaxIm DL from
> http://www.cyanogen.com/downloads/maxim_main.htm.  He'll need to know to
> select the Simulator camera from MaxIm CCD's Setup page once before trying
> any scripting.

I did that (mainly due to the effort by him trying to track this down!)

The problem turns out to be:

pywintypes.com_error: (-2147352567, 'Exception occurred.', (65535, 'MaxIm DL
4', 'Invalid Input', None, 0, 0), None)

This exception is being raised by Python calling Invoke with the correct
dispid, but with only INVOKE_PROPERTYGET and *not* DISPATCH_METHOD.  The
"problem" is that Python's syntax does does distinguish between a property
and a method - so:

 ob.foo()

is (roughly) equivalent to:

 func_ob = getattr(ob, "foo")
 func_ob()

so win32com struggles around this, with the short story being that only
certain error values are "acceptable" when a 'method' is accessed as a
'property'.

Currently, pywin32 only accepts the hresults (DISP_E_MEMBERNOTFOUND,
DISP_E_BADPARAMCOUNT, DISP_E_PARAMNOTOPTIONAL, DISP_E_TYPEMISMATCH and
E_INVALIDARG).  MaxIM returns DISP_E_EXCEPTION, which is not in this list -
and actually should not be.  DISP_E_EXCEPTION means extra exception info is
returned, as reflected in the final part of the above exception.  Ideally,
pywin32 would indirect into the COM excepinfo structure to find the real
error info.  Fortunately for me <wink>, even if pywin32 did sniff deeper, it
would find an error result of -1 (65535) or zero - so would still fail to
find one of its 'acceptable' error results to make the distinction between
'property' and 'method'.

So - the end result is that MaxIM really needs to return a more sane result
when only PROPERTYGET is (or zero args are) requested.  If it is more
convenient for MaxIM to continue to return DISP_E_EXCEPTION and set the real
error in the extended error info, I could agree to make pywin32 handle that
case ;)

Cheers,

Mark



More information about the Python-win32 mailing list