Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > COM server being passed an instance of an interface

Reply
Thread Tools

COM server being passed an instance of an interface

 
 
Phil
Guest
Posts: n/a
 
      05-21-2004
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 ()


 
Reply With Quote
 
 
 
 
Roger Upole
Guest
Posts: n/a
 
      05-22-2004
You ought to be able to do
win32com.client.Dispatch(WL)
to get a usable com object.
hth
Roger

"Phil" <(E-Mail Removed)> wrote in message
news:rXsrc.542$(E-Mail Removed)...
> 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 ()
>
>



 
Reply With Quote
 
 
 
 
Phil
Guest
Posts: n/a
 
      05-22-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" <(E-Mail Removed)> 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" <(E-Mail Removed)> wrote in message
> news:rXsrc.542$(E-Mail Removed)...
> > 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 ()
> >
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Failed to generate a user instance of SQL Server. Only an integratedconnection can generate a user instance. Harlan Messinger ASP .Net 2 03-28-2010 06:51 PM
Failed to generate a user instance of SQL Server due to a failure instarting the process for the user instance. The connection will be closed Homer ASP .Net 1 05-26-2009 12:36 AM
Custom Taglib problems - instead of a single instance per page, I have a single instance per application. chris brat Java 1 05-10-2006 11:16 AM
Setting up a router with 29 Global IPs, BUT can't ping router internal interface from server or server interface from router war_wheelan@yahoo.com Cisco 1 12-14-2005 03:31 PM
Cannot refer to an instance member of a class from within a shared method or shared member initializer without an explicit instance of the class. DJ Dev ASP .Net 3 02-08-2004 04:19 PM



Advertisments