[python-win32] using registered python com server dll from .NET

by Sarah Abdel Razakon 2009-07-06T07:41:18+00:00
--0015174bdd8e4cf2b3046e04a050
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Hi all,
I implemented a python com server and generate an executable and dll using
py2exe tool. then I used regsvr32.exe to register the dll.I got a message
that the registration was successful. Then I tried to add reference to that
dll in .NET. But I can not find my server on the com tab of adding a
reference. I want to mention that I can run the server as a python script
and consume it from .net using late binding. Is there something I'm missing
or doing wrong? I would appreciate any help.
#hello.py
import pythoncom
import sys
class HelloWorld:
#pythoncom.frozen = 1
if hasattr(sys, 'importers'):
_reg_class_spec_ = "__main__.HelloWorld"
_reg_clsctx_ = pythoncom.CLSCTX_LOCAL_SERVER
_reg_clsid_ = '{CDBA816B-E80F-4545-BB68-5A3270C92A74}'
_reg_desc_ = "Python Test COM Server"
_reg_progid_ = "Python.TestServer"
_public_methods_ = ['Hello']
_public_attrs_ = ['softspace', 'noCalls']
_readonly_attrs_ = ['noCalls']
def __init__(self):
self.softspace = 1
self.noCalls = 0
def Hello(self, who):
self.noCalls = self.noCalls + 1
# insert "softspace" number of spaces
print "Hello" + " " * self.softspace + str(who)
return "Hello" + " " * self.softspace + str(who)
if __name__=='__main__':
import sys
if hasattr(sys, 'importers'):
# running as packed executable.
if '--register' in sys.argv[1:] or '--unregister' in sys.argv[1:]:
# --register and --unregister work as usual
import win32com.server.register
win32com.server.register.UseCommandLine(HelloWorld)
else:
# start the server.
from win32com.server import localserver
localserver.serve('CDBA816B-E80F-4545-BB68-5A3270C92A74')
else:
import win32com.server.register
win32com.server.register.UseCommandLine(HelloWorld)
# setup.py
from distutils.core import setup
import py2exe
setup(com_server = ["hello"])
Thanks
--
Sarah Abdelrazak
--0015174bdd8e4cf2b3046e04a050
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Hi all,
I implemented a python com server and generate an executable and dll
using py2exe tool.
then I used regsvr32.exe to register the dll.I got a message that the
registration was successful. Then I tried to add reference to that dll
in .NET. But I can not find my server on the com tab of adding a reference.=
I want to mention that I can run the server as a python script and consume=
it from .net using late binding.
Is there something I'm missing or doing wrong? I would appreciate any h=
elp.#hello.pyimport pythoncomimport sysclas=
s HelloWorld:=A0=A0=A0 #pythoncom.frozen =3D 1=A0=A0=A0 if hasattr(=
sys, 'importers'):
=A0=A0=A0=A0=A0=A0=A0 _reg_class_spec_ =3D "__main__.HelloWorld" =
=A0=A0=A0 _reg_clsctx_ =3D pythoncom.CLSCTX_LOCAL_SERVER=A0=A0=A0 _=
reg_clsid_ =3D '{CDBA816B-E80F-4545-BB68-5A3270C92A74}'=A0=A0=
=A0 _reg_desc_ =3D "Python Test COM Server"
=A0=A0=A0 _reg_progid_ =3D "Python.TestServer"=A0=A0=A0 _publ=
ic_methods_ =3D ['Hello']=A0=A0=A0 _public_attrs_ =3D ['sof=
tspace', 'noCalls']=A0=A0=A0 _readonly_attrs_ =3D ['noC=
alls']=A0=A0=A0 =A0=A0=A0 def __init__(self):
=A0=A0=A0=A0=A0=A0=A0 self.softspace =3D 1=A0=A0=A0=A0=A0=A0=A0 self.no=
Calls =3D 0=A0=A0=A0 def Hello(self, who):=A0=A0=A0=A0=A0=A0=A0=
self.noCalls =3D self.noCalls + 1=A0=A0=A0=A0=A0=A0=A0 # insert "=
softspace" number of spaces=A0=A0=A0=A0=A0=A0=A0 print "Hello=
" + " " * self.softspace + str(who)
=A0=A0=A0=A0=A0=A0=A0 return "Hello" + " " * self.softs=
pace + str(who)if __name__=3D=3D'__main__':=A0=A0=A0 im=
port sys=A0=A0=A0 if hasattr(sys, 'importers'):=A0=A0=A0=A0=
=A0=A0=A0 # running as packed executable.
=A0=A0=A0=A0=A0=A0=A0 if '--register' in sys.argv[1:] or '--unr=
egister' in sys.argv[1:]:=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 # --regi=
ster and --unregister work as usual=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 im=
port win32com.server.register=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 win32com=
.server.register.UseCommandLine(HelloWorld)
=A0=A0=A0=A0=A0=A0=A0 else:=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 # start th=
e server.=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 from win32com.server import =
localserver=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 localserver.serve('CDB=
A816B-E80F-4545-BB68-5A3270C92A74')=A0=A0=A0 else:=A0=A0=A0=A0=
=A0=A0=A0 import win32com.server.register
=A0=A0=A0=A0=A0=A0=A0 win32com.server.register.UseCommandLine(HelloWorld) # setup.pyfrom distutils.core import setupimport py2exes=
etup(com_server =3D ["hello"])Thanks-- =
Sarah Abdelrazak

--0015174bdd8e4cf2b3046e04a050--

Re: [python-win32] using registered python com server dll from .NET

by Michel Claveauon 2009-07-06T11:09:27+00:00.
Hi!
It is normal. COM servers made with Python no have TLB.
dotNET, for read info on a COM server need TLB.
In the same way, dotNET cannot use dynamic COM server (like Python can do
and use it). Except: IronPython (the last beta version) & JScript.Net (the
old, no the recent "manageable" version) can use it.
IMO, it is a dotNET problem, and no a Python problem.
@+
--
Michel Claveau
_______________________________________________
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32