returning from pyCOM Servers

Mark Hammond mhammond at skippinet.com.au
Sat Jan 19 21:14:52 EST 2002


Lebkov wrote:

> Hello All,
> Can somebody explain to me, why Pythoncom puts value returned from
> COM-server's method into first BYREF argument when COM-client intends simply
> to ignore this value?
> 
> I'll be happy to listen any ideas.
> 
> Consider simple COM-server:
> 
> class TestCom:
>     _public_methods_ = ["test"]
>     _reg_clsid_ = '{2af38090-05ac-11d6-9aad-0050da397eca}'
>     _reg_progid_ = 'Python.SimpleServer'
>     def test(self, n):
>         return n*n
> 
> And then call TestCom.test from VBScript:
> set x = CreateObject("Python.SimpleServer")
> n = 2
> x.test n ' We do not want to store x anywhere,
> but after that call x will contain 4!!


VB calls the Python object with a single BYREF argument, and no return 
value.  It does this based on the VB code you used.  VB prefers byref 
args, even internally.

So Python is just doing what is asked of it!  If you really want type 
safety you should consider creating a type library with your interface - 
then both Python and VB will do what you want, not what you say! :)

Mark.




More information about the Python-list mailing list