[python-win32] Why does a python COM server return different data to VBA and Python clients?

Mark Hammond skippy.hammond at gmail.com
Fri Apr 13 04:07:54 CEST 2012


On 10/04/2012 3:40 AM, jeffwelch at earthlink.net wrote:
> My apologies to the list about my earlier question that was in html. My webmail is supposed to default to plain text but clearly did not.
>
> I am trying to write a Python server that will be used by a C++ client. It has taken me quite a while longer than I expected. I have been through the archives and that helped me get to where I am. Many thanks to all those who support these packages.
>
> I am using Python 2.5.1 as it is required by some vendor equipment that I must use.
>
> One of the reasons it took me a while to get this going was that I was trying to test it in Python. Once I switched to testing it in VBA then I made much faster progress.
>
> For demonstration purposes I used the Pippo test in the 'win32com\test' directory. I modified the testpippo.py by adding some code at the start of the testLeaks method. I added the 4 lines:
>
>          in1 = 15
>          inout1 = 99
>          hr= self.object.Method3( in1, inout1)
>          print hr, "retval = %d inout1 = %d"%(hr[0], hr[1])
 >
 >
 > The printed line was "(0, -31) retval = 0 inout1 = -31".
 >

what is Method3 here?  The pippo tests don't have such a method.

But note that in Python, you generally don't see the "hresult" - so it 
would be more accurate to have it read something like:

          results = self.object.Method3( in1, inout1)

as Python doesn't have a concept of "byref" args, the "results" object 
is a tuple with the return value of the function, if any, plus any 
"byref" args created.  In the example above, I'm guessing the function 
has returned 0 and one byref arg was presented, with the new value being 
-31.

In the VB example below, VB does have byrefs, so the out args end up in 
the same argument they were passed in.

I can't explain why VB for -41 for the result when Python got zero 
though, but I also can't find the "method3" to help explain it.

Mark


>
> I get "retval = -41 inout1= -31"  if I execute the VBA code:
>
> Sub TestPippo()
>      Dim obj As Pippo
>      Dim in1 As Long
>      Dim inout1 As Long
>
>      Set obj = CreateObject("Python.Test.Pippo")
>      in1 = 1
>      inout1 = 2
>      retval = obj.Method3(in1, inout1)
>      MsgBox ("retval = " & retval & " inout1 = " & inout1)
>
> End Sub
>
>
> Is there a way to call the same Python Server Method, Method3, so that both Python and VBA receive the same return data?
>
> Regards,
> j
> _______________________________________________
> python-win32 mailing list
> python-win32 at python.org
> http://mail.python.org/mailman/listinfo/python-win32
>




More information about the python-win32 mailing list