Controling types in PythonCOM

Mark Hammond MarkH at
Tue Feb 13 18:05:15 EST 2001

pfenn at wrote:

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

Well that object sucks :)  It should be capable of pulling an int out of any of the variant integer types.

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

Assuming you have makepy pre-generated, yes.

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


So you probably should change it to (2,1) - ie (VT_I2, PARAMFLAG_FIN).  You can't specificy FTOPT with a non variant arg.

By passing (2,0) you _may_ have ended up with a byref int (as some code that sees no flags (ie, 0) gets conservative.)

> com_error: (-2147352567, 'Exception occurred.', (0, None, None, None, 0,
> -2147473646), None)

This is certainly the COM object itself raising the error, not Python.


Nominate Your Favorite Programmers
for the Perl and Python Active Awards!

More information about the Python-list mailing list