By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,905 Members | 900 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,905 IT Pros & Developers. It's quick & easy.

COM server being passed an instance of an interface

P: n/a
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 ()
Jul 18 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
You ought to be able to do
win32com.client.Dispatch(WL)
to get a usable com object.
hth
Roger

"Phil" <pr******@san.rr.com> wrote in message
news:rX***************@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 ()

Jul 18 '05 #2

P: n/a
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" <ru****@hotmail.com> wrote in message
news:40********@127.0.0.1...
You ought to be able to do
win32com.client.Dispatch(WL)
to get a usable com object.
hth
Roger

"Phil" <pr******@san.rr.com> wrote in message
news:rX***************@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 ()


Jul 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.