[python-win32] using registered python com server dll from .NET
Sarah Abdel Razak
sabdelrazak at symbyo.com
Mon Jul 6 09:40:55 CEST 2009
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-win32/attachments/20090706/5f24195d/attachment.htm>
More information about the python-win32
mailing list