COM server being passed an instance of an interface

Discussion in 'Python' started by Phil, May 21, 2004.

  1. Phil

    Phil Guest

    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 ()
     
    Phil, May 21, 2004
    #1
    1. Advertising

  2. Phil

    Roger Upole Guest

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

    "Phil" <> wrote in message
    news:rXsrc.542$...
    > 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 ()
    >
    >
     
    Roger Upole, May 22, 2004
    #2
    1. Advertising

  3. Phil

    Phil Guest

    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" <> wrote in message
    news:40ae9a20_5@127.0.0.1...
    > You ought to be able to do
    > win32com.client.Dispatch(WL)
    > to get a usable com object.
    > hth
    > Roger
    >
    > "Phil" <> wrote in message
    > news:rXsrc.542$...
    > > 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 ()
    > >
    > >

    >
    >
     
    Phil, May 22, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Lucas Tam
    Replies:
    0
    Views:
    425
    Lucas Tam
    Aug 19, 2003
  2. dee
    Replies:
    9
    Views:
    525
    Joseph Byrns
    Apr 15, 2005
  3. Damon
    Replies:
    2
    Views:
    6,249
    Damon
    Feb 3, 2006
  4. SJL
    Replies:
    2
    Views:
    2,359
  5. Anand
    Replies:
    2
    Views:
    915
    Anand
    Sep 11, 2003
Loading...

Share This Page