AW: Error connecting to COMServer

Stefan Migowsky smigowsky at dspace.de
Mon Jun 11 03:53:34 EDT 2001


As you see from the makepy code the ProgId you must use is
"Adder.AddingMachine.1.0". The developer of the COM server
seems not to give a version independent Prog ID. 

So you should use : 
>>>from win32com.client import Dispatch
>>>a = Dispatch("Adder.AddingMachine.1.0")


  Stefan

> 
> 
> Mark Hammond <MarkH at ActiveState.com> wrote in message 
> news:<3B21C08F.8080905 at ActiveState.com>...
> thanks for your answer
> > Mike Müller wrote:
> > 
> > > <VB> 
> > > Dim Adder As New AddingMachine  
> > > </VB>
> > 
> > 
> > It appears the ProgID of the object is simply "AddingMachine"
> 
> The wizard that took me through the creation process says
> Adder.AddingMachine is the ProgID
> and
> AddingMachine is the short name.
> > 
> > 
> > >>>>from win32com.client import Dispatch
> > >>>>a = Dispatch("Adder.AddingMachine")
> > 
> > 
> > Try just using "AddingMachine".
> 
> This results in:
> 
> >>> from win32com.client import Dispatch
> >>> Dispatch("AddingMachine")
> Traceback (innermost last):
>   File "<interactive input>", line 1, in ?
>   File "c:\code\python20\win32com\client\__init__.py", line 94, in
> Dispatch
>     dispatch, userName =
> dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx)
>   File "c:\code\python20\win32com\client\dynamic.py", line 80, in
> _GetGoodDispatchAndUserName
>     return (_GetGoodDispatch(IDispatch, clsctx), userName)
>   File "c:\code\python20\win32com\client\dynamic.py", line 71, in
> _GetGoodDispatch
>     IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx,
> pythoncom.IID_IDispatch)
> com_error: (-2147221005, 'Ung\374ltige Klassenzeichenfolge', None,
> None)
> 
> According to MSDN ... passing an invalid object name  ...
> > 
> > > Can I conclude anything if I look into at the file 
> generated by COM
> > > Makepy?
> > 
> > 
> > Why not open it and see :)  You should find some generated comments 
> > telling you the correct Prog ID to use for all the objects 
> in the library.
> 
> from the generated file:
> # This CoClass is known by the name 'Adder.AddingMachine.1.0'
> 
> But this gives the same result as without the 1.0
> 
> # The following 3 lines may need tweaking for the particular server
> # Candidates are pythoncom.Missing and pythoncom.Empty
> defaultNamedOptArg=pythoncom.Empty
> defaultNamedNotOptArg=pythoncom.Empty
> defaultUnnamedArg=pythoncom.Empty
> 
> Empty and Missing give the same error messages (Adder.AddingMachine or
> just AddingMachine as ProgID).
> 
> Since the file is not long I just appended it (see below).
> 
> Mike
> 
> 
> 
> # Created by makepy.py version 0.3.6
> # By python version 2.0 (#8, Oct 19 2000, 11:30:05) [MSC 32 bit
> (Intel)]
> # From type library '1'
> # On Fri Jun 08 23:15:41 2001
> """AddingMachine 1.0 Type Library"""
> makepy_version = '0.3.6'
> python_version = 0x20000f1
> 
> import win32com.client.CLSIDToClass, pythoncom
> 
> # The following 3 lines may need tweaking for the particular server
> # Candidates are pythoncom.Missing and pythoncom.Empty
> defaultNamedOptArg=pythoncom.Missing
> defaultNamedNotOptArg=pythoncom.Missing
> defaultUnnamedArg=pythoncom.Missing
> 
> CLSID = pythoncom.MakeIID('{904245FB-DD6D-11D3-9835-0000F875E193}')
> MajorVersion = 1
> MinorVersion = 0
> LibraryFlags = 8
> LCID = 0x0
> 
> class CoClassBaseClass:
> 	def __init__(self, oobj=None):
> 		if oobj is None: oobj = pythoncom.new(self.CLSID)
> 		self.__dict__["_dispobj_"] = 
> self.default_interface(oobj)
> 	def __repr__(self):
> 		return "<win32com.gen_py.%s.%s>" % (__doc__,
> self.__class__.__name__)
> 
> 	def __getattr__(self, attr):
> 		d=self.__dict__["_dispobj_"]
> 		if d is not None: return getattr(d, attr)
> 		raise AttributeError, attr
> 	def __setattr__(self, attr, value):
> 		if self.__dict__.has_key(attr): 
> self.__dict__[attr] = value; return
> 		try:
> 			d=self.__dict__["_dispobj_"]
> 			if d is not None:
> 				d.__setattr__(attr, value)
> 				return
> 		except AttributeError:
> 			pass
> 		self.__dict__[attr] = value
> 
> # This CoClass is known by the name 'Adder.AddingMachine.1.0'
> class AddingMachine(CoClassBaseClass): # A CoClass
> 	CLSID = 
> pythoncom.MakeIID("{904245FC-DD6D-11D3-9835-0000F875E193}")
> 	coclass_sources = [
> 	]
> 	coclass_interfaces = [
> 	]
> 
> RecordMap = {
> }
> 
> CLSIDToClassMap = {
> 	'{904245FC-DD6D-11D3-9835-0000F875E193}' : AddingMachine,
> }
> CLSIDToPackageMap = {}
> 
> win32com.client.CLSIDToClass.RegisterCLSIDsFromDict( CLSIDToClassMap )
> -- 
> http://mail.python.org/mailman/listinfo/python-list
> 




More information about the Python-list mailing list