[python-win32] Input-only vs. In/Out Function Parameters
Smith, Brian (CR)
smithbk at aecl.ca
Thu Oct 5 15:45:49 CEST 2006
Hi Mark,
> > 2) VBA was giving me an error like "Expecting 3 return values, got: 2"
> > whenever a function contained an [in, out] parameter. It looks like the
> > extra parameter it is looking for is the HRESULT signifying the success
of
>
> There should be no need to return a HRESULT - but note that the nominated
> return value must be the *first* value returned, with [out] params
following
> in the order they were declared.
That's what I would have expected. In fact, this is the case if I don't use
a type library. However, when using a type library I have to return it
*last* for the object to work from VBA.
> As a result, method4 really should only need 2 return values - I'm not
sure
> why it seems to want more. If you can provide a patch to the pippo sample
> that demonstrates your problem I can dig deeper.
The patches are below. I added two methods with the same signature. The
difference is that Method2() returns two values (as the IDL signature would
suggest) and Method3() returns 3 values, with a 0 as the first value. My
VBA test code (also attached) calls Method3() first and correctly sets
inout1 to -31 and the return value to -41. Note that this occurs even
though the nominated return value is the *last* return value. The call to
Method2() fails with the "Expecting 3 return values, got: 2" error.
My platform is Win XP Pro (SP2), Python 2.3.4, pywin Build 210. I'm testing
using VBA in MS Excel 2000.
Thanks,
Brian
---- pippo.idl patch begin ----
32a33,36
> [id(3), helpstring("method Method2")] HRESULT Method2([in] long
in1, [in, out] long *inout1,
> [out, retval] long *val);
> [id(4), helpstring("method Method3")] HRESULT Method3([in] long
in1, [in, out] long *inout1,
> [out, retval] long *val);
---- pippo.idl patch end ----
---- pippo_server.py patch begin ----
35a36,45
> def Method2(self, in1, inout1):
> new_inout1 = -31
> retVal = -41
> return( new_inout1, retVal )
>
> def Method3(self, in1, inout1):
> new_inout1 = -31
> retVal = -41
> return( 0, new_inout1, retVal )
>
---- pippo_server.py patch end ----
---- VBA test code begin ----
Sub TestPippo()
Dim obj As Pippo
Dim in1 As Long
Dim inout1 As Long
Dim before As String
Dim after As String
Set obj = CreateObject("Python.Test.Pippo")
in1 = 3
inout1 = 5
before = "in1 = " + CStr(in1) + ", inout1 = " + CStr(inout1)
retVal = obj.Method3(in1, inout1)
after = "in1 = " + CStr(in1) + ", inout1 = " + CStr(inout1) + ", retVal
= " + CStr(retVal)
MsgBox before + vbCrLf + after, , "Testing Method3"
in1 = 3
inout1 = 5
before = "in1 = " + CStr(in1) + ", inout1 = " + CStr(inout1)
retVal = obj.Method2(in1, inout1)
after = "in1 = " + CStr(in1) + ", inout1 = " + CStr(inout1) + ", retVal
= " + CStr(retVal)
MsgBox before + vbCrLf + after, , "Testing Method2"
Set obj = Nothing
End Sub
---- VBA test code end ----
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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/python-win32/attachments/20061005/39191d78/attachment.html
More information about the Python-win32
mailing list