#659 Methods with aguments don't work

v1.0 (example)
John Byrne

Hi, I am not sure 100% this is a bug but I wasn't sure how else to ask about it. I can't find any email addresses or mailing lists other than the bug tracking list. I apologize if this is the wrong way to go about raising this issue, and also for the length!

I am using pywin32-218.win32-py2.7 to control WordPerfect X5 with the WP SDK.

I found that after initializing the interface like this:
wp = Dispatch("WordPerfect.PerfectScript")

...I could only call methods that don't take any arguments. So, for exmaple,


would work, but:


would throw the following exception (please ignore the line number because I added some debug statements - it should be 511 not 514):

raceback (most recent call last):
File "wp.py", line 6, in <module>
wp.FileOpen("C:/test.wpd", 370)
File "C:\Python27\lib\site-packages\win32com\client\dynamic.py", line 514, in
ret = self.oleobj.Invoke(retEntry.dispid,0,invoke_type,1)
pywintypes.com_error: (-2147352567, 'Exception occurred.', (65441, u'wpwin15', u
'FileOpen', None, 0, 0), None)

I understand that the error code -2147352567 is fairly generic (http://stackoverflow.com/questions/521759/is-there-a-way-to-decode-numerical-com-error-codes-in-pywin32/521814#521814) and that the application error code 65441 means there is a problem with the arguments.

Stepping through the code, the issue that is happening at this line in dynamic.py (line 511 is the original line number):

ret = self.oleobj.Invoke(retEntry.dispid,0,invoke_type,1)

is that my method is being called without the argument(s) being passed through. I was not sure how this stuff is suppposed to work but I thought that was odd. Reading the documentation for Invoke, I found this:

"If the bResultWanted parameter is False, then the result will be None. Otherwise, the result is determined by the COM object itself (and may still be None)" (http://docs.activestate.com/activepython/2.6/pywin32/PyIDispatch__Invoke_meth.html)

The structure of the pywin32 code made me think that if this call returned None, then it might work, as there seems to be a lot of redenundancy built in. So I made it return None by using False instead of 1 for the last arg, as per the documentation. With this change, my code works perfectly.

I know I could learn more by stepping through the code in more depth but right now I am stuck for time, and have to go with what works. So is this a bug in the code, or am I misunderstanding how it should be used?

-John Byrne


  • Jan

    I see the same issue using Apsentech's Aspen Custom Modeler type library.

    The problem on line 511 in dynamic.py shows my invoke call is also failing with -2147352567. The invoke call requires a string argument which it is not getting at this point in the code.

    I think this is by intention? The exception would drop into a _make_method call which I believe is correct (this is the first time the invoke/method is ever executing).

    I added this error code to winerror.ERRORS_BAD_CONTEXT and the outcome is what I expected (method is "created" and executes correctly).