Yup, still trying to figure this one out
but I've got a little bit more
information.
information.
To summarise: I created a Python COM
Server to be used by Visual Basic
and found an issue with in/out parameters because of the lack of type
information. To fix this, I created a type library but this led to the
following two problems:
and found an issue with in/out parameters because of the lack of type
information. To fix this, I created a type library but this led to the
following two problems:
1) The function calls on the COM object
failed unless I explicitly returned
an HRESULT in addition to returning the other output parameters.
2) After adding an HRESULT as the first element of the returned tuple, I
found that the *last* element of the returned tuple was being used as
the function's return value instead of the *first* value (or second after
the HRESULT?) as expected.
an HRESULT in addition to returning the other output parameters.
2) After adding an HRESULT as the first element of the returned tuple, I
found that the *last* element of the returned tuple was being used as
the function's return value instead of the *first* value (or second after
the HRESULT?) as expected.
I've now tried registering the COM object
with --debug and viewed the trace
output from PythonWin's trace collector utility. After calling a function
that does not add an HRESULT, I ended up getting the following traceback:
output from PythonWin's trace collector utility. After calling a function
that does not add an HRESULT, I ended up getting the following traceback:
Traceback (most recent call
last):
File "C:\DevTools\Python23\lib\site-packages\win32com\universal.py", line 188, in dispatch
raise TypeError, "Expected %s return values, got: %s" % (len(meth._gw_out_args) + 1, len(retVal))
exceptions.TypeError: Expected 3 return values, got: 2
File "C:\DevTools\Python23\lib\site-packages\win32com\universal.py", line 188, in dispatch
raise TypeError, "Expected %s return values, got: %s" % (len(meth._gw_out_args) + 1, len(retVal))
exceptions.TypeError: Expected 3 return values, got: 2
Looking at universal.py, I found this in
the dispatch() function of
class Definition:
class Definition:
...
if type(retVal) == types.TupleType: # Like pythoncom, we special case a tuple.
# However, if they want to return a specific HRESULT,
# then they have to return all of the out arguments
# AND the HRESULT.
if len(retVal) == len(meth._gw_out_args) + 1:
hr = retVal[0]
retVal = retVal[1:]
else:
raise TypeError, "Expected %s return values, got: %s" % (len(meth._gw_out_args) + 1, len(retVal))
else:
retVal = [retVal]
retVal.extend([None] * (len(meth._gw_out_args)-1))
retVal = tuple(retVal)
WriteFromOutTuple(retVal, meth._gw_out_args, argPtr)
return hr
if type(retVal) == types.TupleType: # Like pythoncom, we special case a tuple.
# However, if they want to return a specific HRESULT,
# then they have to return all of the out arguments
# AND the HRESULT.
if len(retVal) == len(meth._gw_out_args) + 1:
hr = retVal[0]
retVal = retVal[1:]
else:
raise TypeError, "Expected %s return values, got: %s" % (len(meth._gw_out_args) + 1, len(retVal))
else:
retVal = [retVal]
retVal.extend([None] * (len(meth._gw_out_args)-1))
retVal = tuple(retVal)
WriteFromOutTuple(retVal, meth._gw_out_args, argPtr)
return hr
I'm not sure what the original intent was,
but the wording in the comment
seems to imply that returning a specific HRESULT should be optional.
However, the code seems to make it mandatory and this would explain
problem #1. I'm not sure if this is a bug or by design.
seems to imply that returning a specific HRESULT should be optional.
However, the code seems to make it mandatory and this would explain
problem #1. I'm not sure if this is a bug or by design.
I also tried looking at the source for
WriteFromOutTuple() to determine the
cause of problem #2, but with limited SWIG knowledge I didn't get far. It
seems like the function verifies data types, but I didn't see where any
"Writing" actually occurred.
cause of problem #2, but with limited SWIG knowledge I didn't get far. It
seems like the function verifies data types, but I didn't see where any
"Writing" actually occurred.
Brian
CONFIDENTIAL AND PRIVILEGED INFORMATION NOTICE This e-mail, and any attachments, may contain information that is confidential, subject to copyright, or exempt from disclosure. Any unauthorized review, disclosure, retransmission, dissemination or other use of or reliance on this information may be unlawful and is strictly prohibited. AVIS D'INFORMATION CONFIDENTIELLE ET PRIVILÉGIÉE Le présent courriel, et toute pièce jointe, peut contenir de l'information qui est confidentielle, régie par les droits d'auteur, ou interdite de divulgation. Tout examen, divulgation, retransmission, diffusion ou autres utilisations non autorisées de l'information ou dépendance non autorisée envers celle-ci peut être illégale et est strictement interdite. |
_______________________________________________ Python-win32 mailing list Python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32