[python-win32] Invalid number of parameters on makepy-generated method

Mark Hammond skippy.hammond at gmail.com
Wed Oct 6 08:46:45 CEST 2010


On 4/10/2010 6:29 PM, Federico Fanton wrote:
> Tim Roberts wrote:
>
>>> It is mostly working, except for a call to a method that accepts a
>>> single optional boolean parameter. When I try to call this method, I get
>>> an "Invalid number of parameters" exception.
>>
>> Is the exception coming from the InvokeTypes call?
>
> Exactly..
> I have a new bit of information though: I noticed that the problem
> arises ONLY when the controlled application (Alibre) is already running,
> while if it's not, there's no exception... Could it be that the "Invalid
> number of parameters" is thrown by something *after* the InvokeTypes?
> That is, could it be an error of the API itself? Or would I get the
> exception elsewhere?

Assuming the exception is a COMException, then yeah, it is the COM 
object itself which is throwing the error - ie, it isn't Python 
complaining about the missing param.

>  >def Close(self, saveSession=False):
>  > """Closes the session and saves the modified session and
>  > sub-sessions, if any, to their original folder locations, if the
>  > saveSession flag is set to true. Use SaveNew or SaveAs if this session
>  > is being saved for the first time"""
>  > return self._oleobj_.InvokeTypes(7, LCID, 1, (24, 0), ((11,
>  > 49),),saveSession )
>
> If I call the Close() method passing pythoncom.Missing, there's no error
> even when Alibre is already open... Is Missing a way to explicitly tell
> "I'm not passing you this parameter, use the default value"?

Exactly - when 'Missing' is used, the win32com bridge doesn't pass 
anything for the arg (ie, the "number of params" Python indicates it has 
passed doesn't include that param).  When it is called as generated by 
makepy though, the parameter is always passed, but using the default 
value supplied by the type-library if one isn't specified by the Python 
code.

This just sounds like a bug in the COM object.

Cheers,

Mark


More information about the python-win32 mailing list