D
Dave
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 DefaultDebugDispatcher
useDispatcher = DefaultDebugDispatcher
else:
useDispatcher = None
class Parent:
_public_methods_ = ['CreateChild', 'KissChild']
_reg_clsid_= "{E8F7F001-DB69-11D2-8531-204C4F4F5020}"
_reg_progid_ = "PythonDemos.Parent"
def CreateChild(self):
child = Child()
print "Our Python child is", child
wrapped = wrap( child, useDispatcher=useDispatcher )
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.UseCommandLine (Parent, debug=debugging)
This is the error in the Python Trace Collector:
Object with win32trace dispatcher created (object=None)
in <ParentChild.Parent instance at 0x04609BE8>._QueryInterface_ with unsupported
IID IPersistStreamInit ({7FD52380-4E07-101B-AE2D-08002B2EC713})
in <ParentChild.Parent instance at 0x04609BE8>._QueryInterface_ with unsupported
IID IPersistPropertyBag ({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\lib\site-packages\win32com\server\dispatcher.py", line 40, i
n _Invoke_
return self.policy._Invoke_(dispid, lcid, wFlags, args)
File "C:\Python23\lib\site-packages\win32com\server\policy.py", line 275, in _
Invoke_
return self._invoke_(dispid, lcid, wFlags, args)
File "C:\Python23\lib\site-packages\win32com\server\policy.py", line 280, in _
invoke_
return S_OK, -1, self._invokeex_(dispid, lcid, wFlags, args, None, None)
File "C:\Python23\lib\site-packages\win32com\server\policy.py", line 541, in _
invokeex_
return func(*args)
File "C:\Python23\ParentChild.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\lib\site-packages\win32com\server\dispatcher.py", line 129,
in _Invoke_
return DispatcherBase._Invoke_(self, dispid, lcid, wFlags, args)
File "C:\Python23\lib\site-packages\win32com\server\dispatcher.py", line 42, i
n _Invoke_
self._HandleException_()
File "C:\Python23\lib\site-packages\win32com\server\dispatcher.py", line 107,
in _HandleException_
reraise()
File "C:\Python23\lib\site-packages\win32com\server\dispatcher.py", line 40, i
n _Invoke_
return self.policy._Invoke_(dispid, lcid, wFlags, args)
File "C:\Python23\lib\site-packages\win32com\server\policy.py", line 275, in _
Invoke_
return self._invoke_(dispid, lcid, wFlags, args)
File "C:\Python23\lib\site-packages\win32com\server\policy.py", line 280, in _
invoke_
return S_OK, -1, self._invokeex_(dispid, lcid, wFlags, args, None, None)
File "C:\Python23\lib\site-packages\win32com\server\policy.py", line 541, in _
invokeex_
return func(*args)
File "C:\Python23\ParentChild.py", line 16, in CreateChild
child = Child()
exceptions.NameError: 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
debugging = 1
if debugging:
from win32com.server.dispatcher import DefaultDebugDispatcher
useDispatcher = DefaultDebugDispatcher
else:
useDispatcher = None
class Parent:
_public_methods_ = ['CreateChild', 'KissChild']
_reg_clsid_= "{E8F7F001-DB69-11D2-8531-204C4F4F5020}"
_reg_progid_ = "PythonDemos.Parent"
def CreateChild(self):
child = Child()
print "Our Python child is", child
wrapped = wrap( child, useDispatcher=useDispatcher )
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.UseCommandLine (Parent, debug=debugging)
This is the error in the Python Trace Collector:
Object with win32trace dispatcher created (object=None)
in <ParentChild.Parent instance at 0x04609BE8>._QueryInterface_ with unsupported
IID IPersistStreamInit ({7FD52380-4E07-101B-AE2D-08002B2EC713})
in <ParentChild.Parent instance at 0x04609BE8>._QueryInterface_ with unsupported
IID IPersistPropertyBag ({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\lib\site-packages\win32com\server\dispatcher.py", line 40, i
n _Invoke_
return self.policy._Invoke_(dispid, lcid, wFlags, args)
File "C:\Python23\lib\site-packages\win32com\server\policy.py", line 275, in _
Invoke_
return self._invoke_(dispid, lcid, wFlags, args)
File "C:\Python23\lib\site-packages\win32com\server\policy.py", line 280, in _
invoke_
return S_OK, -1, self._invokeex_(dispid, lcid, wFlags, args, None, None)
File "C:\Python23\lib\site-packages\win32com\server\policy.py", line 541, in _
invokeex_
return func(*args)
File "C:\Python23\ParentChild.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\lib\site-packages\win32com\server\dispatcher.py", line 129,
in _Invoke_
return DispatcherBase._Invoke_(self, dispid, lcid, wFlags, args)
File "C:\Python23\lib\site-packages\win32com\server\dispatcher.py", line 42, i
n _Invoke_
self._HandleException_()
File "C:\Python23\lib\site-packages\win32com\server\dispatcher.py", line 107,
in _HandleException_
reraise()
File "C:\Python23\lib\site-packages\win32com\server\dispatcher.py", line 40, i
n _Invoke_
return self.policy._Invoke_(dispid, lcid, wFlags, args)
File "C:\Python23\lib\site-packages\win32com\server\policy.py", line 275, in _
Invoke_
return self._invoke_(dispid, lcid, wFlags, args)
File "C:\Python23\lib\site-packages\win32com\server\policy.py", line 280, in _
invoke_
return S_OK, -1, self._invokeex_(dispid, lcid, wFlags, args, None, None)
File "C:\Python23\lib\site-packages\win32com\server\policy.py", line 541, in _
invokeex_
return func(*args)
File "C:\Python23\ParentChild.py", line 16, in CreateChild
child = Child()
exceptions.NameError: 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