COM server being passed an instance of an interface
Phil
pruggera at san.rr.com
Sat May 22 14:08:32 EDT 2004
Hi Roger,
Thanks for the help. So now the program looks like:
import win32com.client
class HelloWorld:
_reg_clsid_ = "{4E797C6A-5969-402F-8101-9C95453CF8F6}"
_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, WL ):
# In VB this looks like Public Sub Hello(ByVal objWL As
WealthLab.IWealthLabAddOn3)
WL = win32com.client.Dispatch(WL)
self.noCalls = self.noCalls + 1
# insert "softspace" number of spaces
return "Hello" + " " * self.softspace + str(self.noCalls) +
str(WL.BarCount())
if __name__=='__main__':
import win32com.server.register
win32com.server.register.UseCommandLine(HelloWorld)
The Python Trace Collector gives me:
Object with win32trace dispatcher created (object=None)
in _GetIDsOfNames_ with '('Hello',)' and '2048'
in _Invoke_ with 1002 0 3 (<PyIDispatch at 0x3d91824 with obj at 0x32eea00>)
Traceback (most recent call last):
File "C:\Python23\Lib\site-packages\win32com\server\dispatcher.py", line 40,
in _Invoke_
return self.policy._Invoke_(dispid, lcid, wFlags, args)
File "C:\Python23\Lib\site-packages\win32com\server\policy.py", line 283, in
_Invoke_
return self._invoke_(dispid, lcid, wFlags, args)
File "C:\Python23\Lib\site-packages\win32com\server\policy.py", line 288, 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 550, in
_invokeex_
return func(*args)
File "G:\Python\Dev\COM Server - win.py", line 27, in Hello
return "Hello" + " " * self.softspace + str(self.noCalls) +
str(WL.BarCount())
File "C:\Python23\Lib\site-packages\win32com\client\dynamic.py", line 489,
in __getattr__
raise AttributeError, "%s.%s" % (self._username_, attr)
AttributeError: <unknown>.BarCount
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,
in _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,
in _Invoke_
return self.policy._Invoke_(dispid, lcid, wFlags, args)
File "C:\Python23\Lib\site-packages\win32com\server\policy.py", line 283, in
_Invoke_
return self._invoke_(dispid, lcid, wFlags, args)
File "C:\Python23\Lib\site-packages\win32com\server\policy.py", line 288, 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 550, in
_invokeex_
return func(*args)
File "G:\Python\Dev\COM Server - win.py", line 27, in Hello
return "Hello" + " " * self.softspace + str(self.noCalls) +
str(WL.BarCount())
File "C:\Python23\Lib\site-packages\win32com\client\dynamic.py", line 489,
in __getattr__
raise AttributeError, "%s.%s" % (self._username_, attr)
exceptions.AttributeError: <unknown>.BarCount
in _Invoke_ with 0 1024 2 ()
in _Invoke_ with 0 1024 2 ()
"Roger Upole" <rupole at hotmail.com> wrote in message
news:40ae9a20_5 at 127.0.0.1...
> You ought to be able to do
> win32com.client.Dispatch(WL)
> to get a usable com object.
> hth
> Roger
>
> "Phil" <pruggera at san.rr.com> wrote in message
> news:rXsrc.542$wO4.145 at twister.socal.rr.com...
> > I am using a Pascal like language (Wealth-Lab) on W2K and call this
> server:
> >
> > class HelloWorld:
> > _reg_clsid_ = "{4E797C6A-5969-402F-8101-9C95453CF8F6}"
> > _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, WL ): # WL is an instance of a interface class that
> > exists in the client
> > # In VB this would look like Public Sub Hello(ByVal objWL As
> > WealthLab.IWealthLabAddOn3)
> > self.noCalls = self.noCalls + 1
> > # insert "softspace" number of spaces
> > return "Hello" + " " * self.softspace + str(self.noCalls) +
> > str(WL.BarCount())
> >
> > if __name__=='__main__':
> > import win32com.server.register
> > win32com.server.register.UseCommandLine(HelloWorld)
> >
> > How do I get the instance of the interface to have its methods? The
> Python
> > Trace Collector gives me:
> >
> > Object with win32trace dispatcher created (object=None)
> > in _GetIDsOfNames_ with '('Hello',)' and '2048'
> >
> > in _Invoke_ with 1002 0 3 (<PyIDispatch at 0x3c5efc4 with obj at
> 0x331ea00>)
> > Traceback (most recent call last):
> > File "C:\Python23\Lib\site-packages\win32com\server\dispatcher.py",
line
> > 40, in _Invoke_
> > return self.policy._Invoke_(dispid, lcid, wFlags, args)
> > File "C:\Python23\Lib\site-packages\win32com\server\policy.py", line
> 283,
> > in _Invoke_
> > return self._invoke_(dispid, lcid, wFlags, args)
> > File "C:\Python23\Lib\site-packages\win32com\server\policy.py", line
> 288,
> > 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
> 550,
> > in _invokeex_
> > return func(*args)
> > File "G:\Python\Dev\COM Server - win.py", line 27, in Hello
> > return "Hello" + " " * self.softspace + str(self.noCalls) +
> > str(WL.BarCount())
> > AttributeError: 'PyIDispatch' object has no attribute 'BarCount'
> > 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, in _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, in _Invoke_
> > return self.policy._Invoke_(dispid, lcid, wFlags, args)
> > File "C:\Python23\Lib\site-packages\win32com\server\policy.py", line
> 283,
> > in _Invoke_
> > return self._invoke_(dispid, lcid, wFlags, args)
> > File "C:\Python23\Lib\site-packages\win32com\server\policy.py", line
> 288,
> > 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
> 550,
> > in _invokeex_
> > return func(*args)
> > File "G:\Python\Dev\COM Server - win.py", line 27, in Hello
> > return "Hello" + " " * self.softspace + str(self.noCalls) +
> > str(WL.BarCount())
> > exceptions.AttributeError: 'PyIDispatch' object has no attribute
> 'BarCount'
> > in _Invoke_ with 0 1024 2 ()
> > in _Invoke_ with 0 1024 2 ()
> >
> >
>
>
More information about the Python-list
mailing list