Controling types in PythonCOM

pfenn at mmm.com pfenn at mmm.com
Tue Feb 13 20:33:02 CET 2001


Hello,

I'm working with an ill behaved type library, where the ODL for a function
specifies a variant integer, but by mucking around in Visual C++, I've
determined that the function really needs a VT_I2.  It appears that
PythonCOM is attempting to pass a VT_I4 which causes an exception.  I am
using the makepy generated  interface, and to make sure I'm doing this
right, I'll show my code:

from win32com.client import Dispatch
xrf = Dispatch('XRaw.Xraw.1')  # Invoked non-dynamically, right?

This is the makepy generated interface for the problem function.  I tried
changing that first (12,17) to a (2,0) after looking at some functions that
did have shorts for parameters but that didn't help.

# The method GetChromatogram is actually a property, but must be used as a
method to correctly pass the arguments
def GetChromatogram(self, FilterIndex=defaultNamedOptArg,
TraceSelector=defaultNamedOptArg, TimeRange=defaultNamedOptArg,
Delay=defaultNamedOptArg):
          """property Chromatogram"""
          return self._ApplyTypes_(0x1e, 2, (12, 0), ((12, 17), (12, 17),
(12, 17), (12, 17)), 'GetChromatogram', None,FilterIndex, TraceSelector,
TimeRange, Delay)

In case I'm interpreting my investigations incorrectly, here's the error I
get in Python when I call this function:

Traceback (most recent call last):
  File "C:\Python20\Pythonwin\pywin\framework\scriptutils.py", line 301, in
RunScript
    exec codeObject in __main__.__dict__
  File "C:\Python20\xcalibur.py", line 146, in ?
    chro3 = df.MIC(1)
  File "C:\Python20\xcalibur.py", line 131, in MIC
    chrom = self.msdet.GetChromatogram(FilterIndex=mode)
  File "c:
\python20\win32com\gen_py\2DDE1FB3-A60F-11D2-BD82-0060978EEB9Cx0x1x0.py",
line 1415, in GetChromatogram
    return self._ApplyTypes_(0x1e, 2, (12, 0), ((12, 17), (12, 17), (12,
17), (12, 17)), 'GetChromatogram', None,FilterIndex, TraceSelector,
TimeRange, Delay)
  File "C:\Python20\win32com\client\__init__.py", line 334, in _ApplyTypes_
    return self._get_good_object_(apply(self._oleobj_.InvokeTypes, (dispid,
0, wFlags, retType, argTypes) + args), user, resultCLSID)
com_error: (-2147352567, 'Exception occurred.', (0, None, None, None, 0,
-2147473646), None)

If I wrap the type library with ATL in Visual C++, the following line
generates a run time error:
IXChromatogramPtr pChrom = pMSDetector->GetChromatogram((long)
1,vtMissing,vtMissing,vtMissing);
but changing the type cast to (short) causes no error to occur.

Thanks ahead of time,

Tom






More information about the Python-list mailing list