<div dir="ltr"><p>Hi all,</p>
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.<br><br>#hello.py<br><br>import pythoncom<br>import sys<br><br><br>class HelloWorld:<br> #pythoncom.frozen = 1<br> if hasattr(sys, 'importers'):<br>
_reg_class_spec_ = "__main__.HelloWorld" <br> _reg_clsctx_ = pythoncom.CLSCTX_LOCAL_SERVER<br> _reg_clsid_ = '{CDBA816B-E80F-4545-BB68-5A3270C92A74}'<br> _reg_desc_ = "Python Test COM Server"<br>
_reg_progid_ = "Python.TestServer"<br> _public_methods_ = ['Hello']<br> _public_attrs_ = ['softspace', 'noCalls']<br> _readonly_attrs_ = ['noCalls']<br> <br> def __init__(self):<br>
self.softspace = 1<br> self.noCalls = 0<br><br> def Hello(self, who):<br> self.noCalls = self.noCalls + 1<br> # insert "softspace" number of spaces<br> print "Hello" + " " * self.softspace + str(who)<br>
return "Hello" + " " * self.softspace + str(who)<br><br>if __name__=='__main__':<br> import sys<br> if hasattr(sys, 'importers'):<br> # running as packed executable.<br>
if '--register' in sys.argv[1:] or '--unregister' in sys.argv[1:]:<br> # --register and --unregister work as usual<br> import win32com.server.register<br> win32com.server.register.UseCommandLine(HelloWorld)<br>
else:<br> # start the server.<br> from win32com.server import localserver<br> localserver.serve('CDBA816B-E80F-4545-BB68-5A3270C92A74')<br> else:<br> import win32com.server.register<br>
win32com.server.register.UseCommandLine(HelloWorld) <br><br># setup.py<br>from distutils.core import setup<br>import py2exe<br>setup(com_server = ["hello"])<br><br clear="all">Thanks<br>-- <br>Sarah Abdelrazak<br>
</div>