pywin32 custom i/f COM servers do not support variable or optional args

Philip Rittenhouse phil at dspfactory.com
Wed Jun 30 21:25:47 CEST 2004


I have discovered a couple of problems with the way the universal
gateway code handles optional parameters and variable argument lists
in COM servers.

It appears to only be a problem when you use the custom interface. 

What I found was that variable argument lists are not detected at
all.  Instead they are just converted from SAFEARRAYs to a Python
list.

Similarly, omitted optional parameters (which are sent by COM
as VARIANTs with value of DISP_E_PARAMNOTFOUND) are converted
to Python integers with the integer value of DISP_E_PARAMNOTFOUND.

I have made changes to univgw_dataconv.cpp to fix these problems
but before I submit a patch, I'd like to make sure the changes make
sense.  To fix the optional argument problem, the code now checks
VT_VARIANTS to see if they are VT_ERRORs with the value 
DISP_E_PARAMNOTFOUND.  If they are, the argument is dropped, and
presumably the Python method will have a suitable default to use in
its place.

The variable argument code was a little more tricky.  I couldn't see
any easy way to test if a method had the vararg property set, so I 
just assumed that any pointer to a SAFEARRAY of VARIANTS used as the 
last argument must represent a variable argument list.  It then converts 
the array and expands the parameter tuple to fit the new arguments.


Finally, I made a change to universal.py to handle the case where
the variable argument list SAFEARRAY is declared [in, out] (as opposed
to just [in]).  This was required to support VB.  In 
_GenerateOutArgTuple() I check if the method is a variable argument 
method and if so, I remove the variable arg parameter from the list of 
outputs.


Thanks,
Phil



More information about the Python-list mailing list