Help, pls: COM local server factory class

Bill Bell bill-bell at bill-bell.hamilton.on.ca
Mon Jun 18 21:35:43 CEST 2001


Esteemed Pythonistas:

The code that appears below is intended to define a COM local 
server. (My understanding of some earlier messages on this list is 
that it should result in a singleton by default.)

There are two classes in the server, one of them being a factory for 
the other (and defined near the end of the code).

Two questions I'd appreciate answers to (bearing in mind I'm new to 
Python):

1. How close is the factory class to what I ~should~ be doing?

2. What is the meaning of the following?

>>> import win32com.client, msvcrt, pythoncom
>>> factory = 
win32com.client.Dispatch("WebPASS.ServerFactory1")
>>> server = factory.Factory()
Traceback (most recent call last):
  File "<interactive input>", line 1, in ?
  File "<COMObject WebPASS.ServerFactory1>", line 2, in Factory
com_error: (-2147352567, 'Exception occurred.', (0, 'Python COM 
Server Internal Error', 'Unexpected Python Error: 
exceptions.TypeError: Objects for SAFEARRAYS must be 
sequences (of sequences), or a buffer object.', None, 0, -
2147467259), None)
>>> 

Thanks for any help you can render.

Bill

<SNIP wxPython stuff>
def GUI():
    try:
        WebPASSPath = os.path.split(__file__)[0]
        os.chdir(WebPASSPath)
    except:
        pass
    global app
    app = WebPASSApp(0)
    app.MainLoop()

from threading import Thread

class GUIThread(Thread):
    def _init_(self):
        Thread._init_(self)
    def run(self):
        GUI()

def main():
    t = GUIThread()
    t.start()
    time.sleep(5)
    app.frame.ReportActivity("... from main()")

class COMServer:
    _reg_clsid_ = "{D471BE26-C3C8-4773-B438-041BA612C563}"
    _reg_desc_ = "WebPASS COM Server"
    _reg_progid_ = "WebPASS.Server1"
    _public_methods_ = ['Report']
    _reg_clsctx_ = pythoncom.CLSCTX_LOCAL_SERVER
    
    def __init__(self):
        main()

    def Report(self, msg):
        app.frame.ReportActivity("... from COMServer.Report(self) " + 
str(msg))

class COMServerFactory:
    _reg_clsid_ = "{ED8F1767-4035-4c20-8162-24C2EE9E380C}"
    _reg_desc_ = "WebPASS COM Server Factory"
    _reg_progid_ = "WebPASS.ServerFactory1"
    _public_methods_ = ['Factory']
    _reg_clsctx_ = pythoncom.CLSCTX_LOCAL_SERVER

    def __init__(self):
        self.theCOMServer = None

    def Factory(self):
        if self.theCOMServer == None:
            self.theCOMServer = COMServer()
        return self.theCOMServer

if __name__ == '__main__':
    import win32com.server.register
    win32com.server.register.UseCommandLine(COMServer)
    win32com.server.register.UseCommandLine(COMServerFactory)





More information about the Python-list mailing list