Python COM server

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dave

    Python COM server

    I have been trying an example from the Python Programming on Win32 book on the lastest versions of python (2.3.3) and win32all (build 163). I create the COM object and try to call it from VB but i can't seem to create the child.

    debugging = 1
    if debugging:
    from win32com.server .dispatcher import DefaultDebugDis patcher
    useDispatcher = DefaultDebugDis patcher
    else:
    useDispatcher = None

    class Parent:
    _public_methods _ = ['CreateChild', 'KissChild']
    _reg_clsid_= "{E8F7F001-DB69-11D2-8531-204C4F4F5020}"
    _reg_progid_ = "PythonDemos.Pa rent"

    def CreateChild(sel f):
    child = Child()
    print "Our Python child is", child
    wrapped = wrap( child, useDispatcher=u seDispatcher )
    print "Returning wrapped", wrapped
    return wrapped

    def KissChild(self, child):
    print "KissChild called with child", child
    dispatch = win32com.client .Dispatch(child )
    print "KissChild called with child named", dispatch.Name

    child = umwrap(child)
    print "The Python child is", child

    class Child:
    _public_methods _ = []
    _public_attrs_ = ['Name']
    def __init__(self):
    self.name = "Unnamed"

    if __name__ == '__main__':
    import win32com.server .register
    win32com.server .register.UseCo mmandLine (Parent, debug=debugging )


    This is the error in the Python Trace Collector:

    Object with win32trace dispatcher created (object=None)
    in <ParentChild.Pa rent instance at 0x04609BE8>._Qu eryInterface_ with unsupported
    IID IPersistStreamI nit ({7FD52380-4E07-101B-AE2D-08002B2EC713})
    in <ParentChild.Pa rent instance at 0x04609BE8>._Qu eryInterface_ with unsupported
    IID IPersistPropert yBag ({37D84F60-42CB-11CE-8135-00AA004BB851})
    in _GetIDsOfNames_ with '('CreateChild' ,)' and '1033'

    in _Invoke_ with 1000 1033 3 ()
    Traceback (most recent call last):
    File "C:\Python23\li b\site-packages\win32c om\server\dispa tcher.py", line 40, i
    n _Invoke_
    return self.policy._In voke_(dispid, lcid, wFlags, args)
    File "C:\Python23\li b\site-packages\win32c om\server\polic y.py", line 275, in _
    Invoke_
    return self._invoke_(d ispid, lcid, wFlags, args)
    File "C:\Python23\li b\site-packages\win32c om\server\polic y.py", line 280, in _
    invoke_
    return S_OK, -1, self._invokeex_ (dispid, lcid, wFlags, args, None, None)
    File "C:\Python23\li b\site-packages\win32c om\server\polic y.py", line 541, in _
    invokeex_
    return func(*args)
    File "C:\Python23\Pa rentChild.py", line 16, in CreateChild
    child = Child()
    NameError: global name 'Child' is not defined
    pythoncom error: Python error invoking COM method.
    Traceback (most recent call last):
    File "C:\Python23\li b\site-packages\win32c om\server\dispa tcher.py", line 129,
    in _Invoke_
    return DispatcherBase. _Invoke_(self, dispid, lcid, wFlags, args)
    File "C:\Python23\li b\site-packages\win32c om\server\dispa tcher.py", line 42, i
    n _Invoke_
    self._HandleExc eption_()
    File "C:\Python23\li b\site-packages\win32c om\server\dispa tcher.py", line 107,
    in _HandleExceptio n_
    reraise()
    File "C:\Python23\li b\site-packages\win32c om\server\dispa tcher.py", line 40, i
    n _Invoke_
    return self.policy._In voke_(dispid, lcid, wFlags, args)
    File "C:\Python23\li b\site-packages\win32c om\server\polic y.py", line 275, in _
    Invoke_
    return self._invoke_(d ispid, lcid, wFlags, args)
    File "C:\Python23\li b\site-packages\win32c om\server\polic y.py", line 280, in _
    invoke_
    return S_OK, -1, self._invokeex_ (dispid, lcid, wFlags, args, None, None)
    File "C:\Python23\li b\site-packages\win32c om\server\polic y.py", line 541, in _
    invokeex_
    return func(*args)
    File "C:\Python23\Pa rentChild.py", line 16, in CreateChild
    child = Child()
    exceptions.Name Error: global name 'Child' is not defined


    The COM object always seems to fail whenever I call a subclass saying that its not defined. I'm not to sure what the problem is. Any help would be appreciated.

    Thanks

    David
Working...