On Tue, 08 Nov 2022 15:53:19 -0000, Brian Johnson <br...@brian3johnson.me> declaimed the following:
>Hi python-win32 community.I am trying to get this toy COM server (code is >below) to work. It is the sample code from "Python Programming for Win32" and >adapted for python 3.10. When I test it using VBA in Word, I get this >error:Run-time error '429':ActiveX component can't create objectI don't know >if I am missing one a required _reg_param_ that is needed for Win10.Is there >is an extra step I need to take to register/run the COM server?I don't know if >win32com.server.localserver.serve [] is necessary.Does the class need an >__init__ method to do something?I appreciate any help or insight into getting >this to work. Thank you!Sincerely, BrianContext:Windows 10, python 3.10, >Office 365, running python code as AdministratorI have verified the python >class works in python only.I tried registering/unregistering using both >options shown below. Both appear to work - no error messages. I can find info >about the COM Server using Regedit.I tried the --debug flag, but it didn't >provide any >verbosity.I'm learning COM, but the info about it is sparse and generally very >abstract.Python script, SimpleCOMServer.py:"""A sample COM server - almost as >small as they come."""# import sysimport pythoncomimport >win32com.server.registerclass PythonUtilities: """We expose a simple method >in a Python COM object.""" _reg_clsctx_ = pythoncom.CLSCTX_LOCAL_SERVER >_public_methods_ = ["SplitString"] _reg_progid_ = "PythonDemos.Utilities" > _reg_desc_ = "PythonDemos Test COM Server" # NEVER copy the following ID > # Use "print(pythoncom.CreateGUID())" to made a new on. _reg_clsid_ = >"{819E8336-00B5-4025-979A-46EE1EF411B7}" # for Python 3.7+ # >https://stackoverflow.com/questions/1054849/consuming-python-com-server-from-net > _reg_verprogid_ = "PythonDemos.Utilities.1" # <filename>.<classname> >_reg_class_spec_ = "SimpleCOMServer.PythonUtilities" def SplitString(self, >val, separator=None): """Split a string by a separator.""" # if >separator is >not None: # return val.split(separator) # else: # >return val.split() if separator is not None: return >str(val).split(str(separator)) else: return >str(val).split()# Add code so that when this script is run by python e.e, it >self-registers.if __name__ == "__main__": print("Registering COM >server...") win32com.server.register.UseCommandLine(PythonUtilities) # >if "--register" in sys.argv[1:] or "--unregister" in sys.argv[1:]: # >win32com.server.register.UseCommandLine(PythonUtilities) # else: # # >start the server. # from win32com.server.localserver import serve # > serve(["{819E8336-00B5-4025-979A-46EE1EF411B7}"])Word VBA macro:Sub >TestPython() Dim PythonUtils As Object Set PythonUtils = >CreateObject("PythonDemos.Utilities") response = >PythonUtils.SplitString("Hello from VB") For Each Item In response >MsgBox Item NextEnd Sub (UGH! what type of line endings is your client sending?) 32-bit or 64-bit? Office 365 may be 32-bit applications, and will need a 32-bit Python COM server. -- Wulfraed Dennis Lee Bieber AF6VN wlfr...@ix.netcom.com http://wlfraed.microdiversity.freeddns.org/ _______________________________________________ python-win32 mailing list python-win32@python.org https://mail.python.org/mailman/listinfo/python-win32