Hi,

I have a problem connecting to a COM server with a small test script using 
python 2.3.5 as well as 2.4.1:

import win32com.client
from win32com.client import gencache

def main():
    g1  = gencache.EnsureModule('{9C3BB401-114D-11D4-AC72-00105A4925FC}', 0, 1, 
3)

    theCADdy = win32com.client.Dispatch('CADdy.CADdy')
    print repr(theCADdy)                                                # => 
<COMObject CADdy.CADdy>
    theCADdy = g1.ICADdy(theCADdy)                              # => 
<win32com.gen_py.CADdyCOM 1.3 (CADdy) Type Library.ICADdy instance at 
0x21362568>
    print repr(theCADdy)
    v1 = theCADdy.VersionNo

if __name__ == '__main__':
    main()


I got the following error message:

C:\Programme\Python\lib\site-packages\win32com\client\__init__.py in 
__getattr__(self, attr)
    453                 if args is None:
    454                         raise AttributeError, "'%s' object has no 
attribute '%s'" % (repr(self), attr)
--> 455                 return self._ApplyTypes_(*args)
    456
    457         def __setattr__(self, attr, value):

C:\Programme\Python\lib\site-packages\win32com\client\__init__.py in 
_ApplyTypes_(self, dispid, wFlags, retType, argTypes, user, resultCLSID, *args)
    444         def _ApplyTypes_(self, dispid, wFlags, retType, argTypes, user,
    445                      resultCLSID, *args):
--> 446                 return self._get_good_object_(
    447                     self._oleobj_.InvokeTypes(
    448                               dispid, 0, wFlags, retType, argTypes, *arg
s),

com_error: (-2147319779, 'Bibliothek nicht registriert.', None, None)
WARNING: Failure executing file: <Test3.py>

I have no idea what is going wrong with my test program. Connecting to MS Excel 
is no problem. Can someone tell me how do I correctly use the pythonCOM
module. I have no problem connecting the CADdy COM server from VB and C++. Is 
there anything wrong inside my COM type libraries?

With best regards 

Johannes



The following is the information about the type library provided by the OLE 
viewer:

// Generated .IDL file (by the OLE/COM Object Viewer)
// 
// typelib filename: CADdy.tlb

[
  uuid(9C3BB401-114D-11D4-AC72-00105A4925FC),
  version(1.3),
  helpstring("CADdyCOM 1.3 (CADdy) Type Library")
]
library CADDYLib
{
    // TLib :     // TLib : OLE Automation : 
{00020430-0000-0000-C000-000000000046}
    importlib("stdole2.tlb");

    // Forward declare all types defined in this typelib
    interface ICADdyAddIn;
    interface ICADdy;
    interface IEnumCADdyAddIn;
    interface ICADdyAddIns;
    interface ISupportErrorInfo;

    typedef enum {
        ADDIN_E_ERRONEOUSADDIN = -2147220992,
        ADDIN_E_ALREADYSTARTED = -2147220991,
        ADDIN_E_INAPPROPRIATESERVER = -2147220990,
        ADDIN_E_CANTCREATESERVER = -2147220989
    } ADDINHRESULTS;

    [
      odl,
      uuid(14F65AE1-4671-11D4-8B1A-00105A49278B),
      helpstring("ICADdyAddIn Interface"),
      dual,
      oleautomation
    ]
    interface ICADdyAddIn : IDispatch {
        [id(0x00000001), helpstring("method Init")]
        HRESULT Init([in] ICADdy* theCADdy);
        [id(0x00000002), helpstring("method Exit")]
        HRESULT Exit();
        [id(0x00000003), propget, helpstring("property CLSID")]
        HRESULT CLSID([out, retval] BSTR* pcCLSID);
        [id(0x00000004), propget, helpstring("property ProgID")]
        HRESULT ProgId([out, retval] BSTR* pcProgId);
        [id(0x00000005), propget, helpstring("property Description")]
        HRESULT Description([out, retval] BSTR* pcDescription);
    };

    [
      odl,
      uuid(D330F3E0-0F91-11D4-AC6E-00105A4925FC),
      helpstring("ICADdy Interface"),
      dual,
      oleautomation
    ]
    interface ICADdy : IDispatch {
        [id(0x00000001), propget, helpstring("property FrameManager")]
        HRESULT FrameManager([out, retval] IDispatch** ppICADdyFrameManager);
        [id(0x00000002), propget, helpstring("property ModelManager")]
        HRESULT ModelManager([out, retval] IDispatch** ppICADdyModelManager);
        [id(0x00000003), propget, helpstring("property UIManager")]
        HRESULT UIManager([out, retval] IDispatch** ppICADdyUIManager);
        [id(0x00000004), propget, helpstring("property Manager")]
        HRESULT Manager(
                        [in] BSTR __MIDL_0025, 
                        [out, retval] IDispatch** ppICADdyDimensionManager);
        [id(0x00000005), propget, helpstring("property ExeDirectory")]
        HRESULT ExeDirectory([out, retval] BSTR* pbstrDirectory);
        [id(0x00000006), propget, helpstring("property HomeDirectory")]
        HRESULT HomeDirectory([out, retval] BSTR* pbstrDirectory);
        [id(0x00000007), propget, helpstring("property Name")]
        HRESULT Name([out, retval] BSTR* pbstrName);
        [id(0x00000008), propget, helpstring("property VersionNo")]
        HRESULT VersionNo([out, retval] long* lVersion);
        [id(0x00000009), propget, helpstring("property ReleaseNo")]
        HRESULT ReleaseNo([out, retval] long* lRelease);
    };

    [
      odl,
      uuid(14F65AE3-4671-11D4-8B1A-00105A49278B),
      helpstring("IEnumCADdyAddIn Interface"),
      oleautomation
    ]
    interface IEnumCADdyAddIn : IUnknown {
        [helpstring("Next")]
        HRESULT _stdcall Next(
                        [in] unsigned long i4Count, 
                        [out] ICADdyAddIn** __MIDL_0015, 
                        [out] unsigned long* pi4Fetched);
        [helpstring("Skip")]
        HRESULT _stdcall Skip([in] unsigned long __MIDL_0016);
        [helpstring("Reset")]
        HRESULT _stdcall Reset();
        [helpstring("Clone")]
        HRESULT _stdcall Clone([out] IEnumCADdyAddIn** __MIDL_0017);
    };

    [
      odl,
      uuid(14F65AE2-4671-11D4-8B1A-00105A49278B),
      helpstring("ICADdyAddIns Interface"),
      dual,
      nonextensible,
      oleautomation
    ]
    interface ICADdyAddIns : IDispatch {
        [id(00000000), propget, helpstring("Item")]
        HRESULT Item(
                        [in] long __MIDL_0018, 
                        [out, retval] ICADdyAddIn** __MIDL_0019);
        [id(0xfffffffc), propget, restricted, helpstring("_NewEnum")]
        HRESULT _NewEnum([out, retval] IUnknown** __MIDL_0020);
        [id(0x00000001), propget, helpstring("property Count")]
        HRESULT Count([out, retval] long* __MIDL_0021);
        [id(0x00000002), helpstring("Start")]
        HRESULT Start(
                        [in] BSTR __MIDL_0022, 
                        [out, retval] ICADdyAddIn** __MIDL_0023);
        [id(0x00000003), helpstring("Stop")]
        HRESULT Stop([in] ICADdyAddIn* __MIDL_0024);
        [id(0x00000004), helpstring("StopAll")]
        HRESULT StopAll();
    };

    [
      uuid(D330F3E1-0F91-11D4-AC6E-00105A4925FC),
      helpstring("CADdy Class"),
      noncreatable
    ]
    coclass CoCADdy {
        [default] interface ICADdy;
        interface ISupportErrorInfo;
    };

    [
      odl,
      uuid(DF0B3D60-548F-101B-8E65-08002B2BD119)
    ]
    interface ISupportErrorInfo : IUnknown {
        HRESULT _stdcall InterfaceSupportsErrorInfo([in] GUID* riid);
    };

    [
      uuid(3F5B2591-4768-11D4-8B1C-00105A49278B),
      helpstring("CADdyAddIn Collection")
    ]
    coclass CADdyAddIns {
        [default] interface ICADdyAddIns;
        interface ISupportErrorInfo;
    };
};

And the python file generated by g1  = 
gencache.EnsureModule('{9C3BB401-114D-11D4-AC72-00105A4925FC}', 0, 1, 3)

# -*- coding: mbcs -*-
# Created by makepy.py version 0.4.91
# By python version 2.3.5 (#62, Mar 22 2005, 21:53:13) [MSC v.1200 32 bit 
(Intel)]
# From type library '{9C3BB401-114D-11D4-AC72-00105A4925FC}'
# On Mon Jun 20 16:06:02 2005
"""CADdyCOM 1.3 (CADdy) Type Library"""
makepy_version = '0.4.91'
python_version = 0x20305f0

import win32com.client.CLSIDToClass, pythoncom
import win32com.client.util
from pywintypes import IID
from win32com.client import Dispatch

# 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

CLSID = IID('{9C3BB401-114D-11D4-AC72-00105A4925FC}')
MajorVersion = 1
MinorVersion = 3
LibraryFlags = 8
LCID = 0x0

class constants:
        ADDIN_E_ALREADYSTARTED        =-2147220991 # from enum ADDINHRESULTS
        ADDIN_E_CANTCREATESERVER      =-2147220989 # from enum ADDINHRESULTS
        ADDIN_E_ERRONEOUSADDIN        =-2147220992 # from enum ADDINHRESULTS
        ADDIN_E_INAPPROPRIATESERVER   =-2147220990 # from enum ADDINHRESULTS

from win32com.client import DispatchBaseClass
class ICADdy(DispatchBaseClass):
        """ICADdy Interface"""
        CLSID = IID('{D330F3E0-0F91-11D4-AC6E-00105A4925FC}')
        coclass_clsid = IID('{D330F3E1-0F91-11D4-AC6E-00105A4925FC}')

        # The method Manager is actually a property, but must be used as a 
method to correctly pass the arguments
        def Manager(self, _MIDL_0025_=defaultNamedNotOptArg):
                """property Manager"""
                ret = self._oleobj_.InvokeTypes(4, LCID, 2, (9, 0), ((8, 
1),),_MIDL_0025_)
                if ret is not None:
                        ret = Dispatch(ret, 'Manager', None, UnicodeToString=0)
                return ret

        _prop_map_get_ = {
                "ExeDirectory": (5, 2, (8, 0), (), "ExeDirectory", None),
                "FrameManager": (1, 2, (9, 0), (), "FrameManager", None),
                "HomeDirectory": (6, 2, (8, 0), (), "HomeDirectory", None),
                "ModelManager": (2, 2, (9, 0), (), "ModelManager", None),
                "Name": (7, 2, (8, 0), (), "Name", None),
                "ReleaseNo": (9, 2, (3, 0), (), "ReleaseNo", None),
                "UIManager": (3, 2, (9, 0), (), "UIManager", None),
                "VersionNo": (8, 2, (3, 0), (), "VersionNo", None),
        }
        _prop_map_put_ = {
        }

class ICADdyAddIn(DispatchBaseClass):
        """ICADdyAddIn Interface"""
        CLSID = IID('{14F65AE1-4671-11D4-8B1A-00105A49278B}')
        coclass_clsid = None

        def Exit(self):
                """method Exit"""
                return self._oleobj_.InvokeTypes(2, LCID, 1, (24, 0), (),)

        def Init(self, theCADdy=defaultNamedNotOptArg):
                """method Init"""
                return self._oleobj_.InvokeTypes(1, LCID, 1, (24, 0), ((9, 
1),),theCADdy)

        _prop_map_get_ = {
                "CLSID": (3, 2, (8, 0), (), "CLSID", None),
                "Description": (5, 2, (8, 0), (), "Description", None),
                "ProgId": (4, 2, (8, 0), (), "ProgId", None),
        }
        _prop_map_put_ = {
        }

class ICADdyAddIns(DispatchBaseClass):
        """ICADdyAddIns Interface"""
        CLSID = IID('{14F65AE2-4671-11D4-8B1A-00105A49278B}')
        coclass_clsid = IID('{3F5B2591-4768-11D4-8B1C-00105A49278B}')

        # Result is of type ICADdyAddIn
        # The method Item is actually a property, but must be used as a method 
to correctly pass the arguments
        def Item(self, _MIDL_0018_=defaultNamedNotOptArg):
                """Item"""
                ret = self._oleobj_.InvokeTypes(0, LCID, 2, (9, 0), ((3, 
1),),_MIDL_0018_)
                if ret is not None:
                        ret = Dispatch(ret, 'Item', 
'{14F65AE1-4671-11D4-8B1A-00105A49278B}', UnicodeToString=0)
                return ret

        # Result is of type ICADdyAddIn
        def Start(self, _MIDL_0022_=defaultNamedNotOptArg):
                """Start"""
                ret = self._oleobj_.InvokeTypes(2, LCID, 1, (9, 0), ((8, 
1),),_MIDL_0022_)
                if ret is not None:
                        ret = Dispatch(ret, 'Start', 
'{14F65AE1-4671-11D4-8B1A-00105A49278B}', UnicodeToString=0)
                return ret

        def Stop(self, _MIDL_0024_=defaultNamedNotOptArg):
                """Stop"""
                return self._oleobj_.InvokeTypes(3, LCID, 1, (24, 0), ((9, 
1),),_MIDL_0024_)

        def StopAll(self):
                """StopAll"""
                return self._oleobj_.InvokeTypes(4, LCID, 1, (24, 0), (),)

        _prop_map_get_ = {
                "Count": (1, 2, (3, 0), (), "Count", None),
        }
        _prop_map_put_ = {
        }
        # Default method for this class is 'Item'
        def __call__(self, _MIDL_0018_=defaultNamedNotOptArg):
                """Item"""
                ret = self._oleobj_.InvokeTypes(0, LCID, 2, (9, 0), ((3, 
1),),_MIDL_0018_)
                if ret is not None:
                        ret = Dispatch(ret, '__call__', 
'{14F65AE1-4671-11D4-8B1A-00105A49278B}', UnicodeToString=0)
                return ret

        # str(ob) and int(ob) will use __call__
        def __unicode__(self, *args):
                try:
                        return unicode(self.__call__(*args))
                except pythoncom.com_error:
                        return repr(self)
        def __str__(self, *args):
                return str(self.__unicode__(*args))
        def __int__(self, *args):
                return int(self.__call__(*args))
        def __iter__(self):
                "Return a Python iterator for this object"
                ob = self._oleobj_.InvokeTypes(-4,LCID,2,(13, 10),())
                return win32com.client.util.Iterator(ob)
        def _NewEnum(self):
                "Create an enumerator from this object"
                return 
win32com.client.util.WrapEnum(self._oleobj_.InvokeTypes(-4,LCID,2,(13, 
10),()),'{14F65AE1-4671-11D4-8B1A-00105A49278B}')
        def __getitem__(self, index):
                "Allow this class to be accessed as a collection"
                if not self.__dict__.has_key('_enum_'):
                        self.__dict__['_enum_'] = self._NewEnum()
                return self._enum_.__getitem__(index)
        #This class has Count() property - allow len(ob) to provide this
        def __len__(self):
                return self._ApplyTypes_(*(1, 2, (3, 0), (), "Count", None))
        #This class has a __len__ - this is needed so 'if object:' always 
returns TRUE.
        def __nonzero__(self):
                return True

from win32com.client import CoClassBaseClass
# This CoClass is known by the name 'AddIns.CADdyAddIns.1'
class CADdyAddIns(CoClassBaseClass): # A CoClass
        # CADdyAddIn Collection
        CLSID = IID('{3F5B2591-4768-11D4-8B1C-00105A49278B}')
        coclass_sources = [
        ]
        coclass_interfaces = [
                ICADdyAddIns,
        ]
        default_interface = ICADdyAddIns

# This CoClass is known by the name 'CADdy.CADdy.1'
class CoCADdy(CoClassBaseClass): # A CoClass
        # CADdy Class
        CLSID = IID('{D330F3E1-0F91-11D4-AC6E-00105A4925FC}')
        coclass_sources = [
        ]
        coclass_interfaces = [
                ICADdy,
        ]
        default_interface = ICADdy

ICADdy_vtables_dispatch_ = 1
ICADdy_vtables_ = [
        (('FrameManager', 'ppICADdyFrameManager'), 1, (1, (), [(16393, 10, 
None, None)], 1, 2, 4, 0, 28, (3, 0, None, None), 0)),
        (('ModelManager', 'ppICADdyModelManager'), 2, (2, (), [(16393, 10, 
None, None)], 1, 2, 4, 0, 32, (3, 0, None, None), 0)),
        (('UIManager', 'ppICADdyUIManager'), 3, (3, (), [(16393, 10, None, 
None)], 1, 2, 4, 0, 36, (3, 0, None, None), 0)),
        (('Manager', '__MIDL_0025', 'ppICADdyDimensionManager'), 4, (4, (), 
[(8, 1, None, None), (16393, 10, None, None)], 1, 2, 4, 0, 40, (3, 0, None, 
None), 0)),
        (('ExeDirectory', 'pbstrDirectory'), 5, (5, (), [(16392, 10, None, 
None)], 1, 2, 4, 0, 44, (3, 0, None, None), 0)),
        (('HomeDirectory', 'pbstrDirectory'), 6, (6, (), [(16392, 10, None, 
None)], 1, 2, 4, 0, 48, (3, 0, None, None), 0)),
        (('Name', 'pbstrName'), 7, (7, (), [(16392, 10, None, None)], 1, 2, 4, 
0, 52, (3, 0, None, None), 0)),
        (('VersionNo', 'lVersion'), 8, (8, (), [(16387, 10, None, None)], 1, 2, 
4, 0, 56, (3, 0, None, None), 0)),
        (('ReleaseNo', 'lRelease'), 9, (9, (), [(16387, 10, None, None)], 1, 2, 
4, 0, 60, (3, 0, None, None), 0)),
]

ICADdyAddIn_vtables_dispatch_ = 1
ICADdyAddIn_vtables_ = [
        (('Init', 'theCADdy'), 1, (1, (), [(9, 1, None, 
"IID('{D330F3E0-0F91-11D4-AC6E-00105A4925FC}')")], 1, 1, 4, 0, 28, (3, 0, None, 
None), 0)),
        (('Exit',), 2, (2, (), [], 1, 1, 4, 0, 32, (3, 0, None, None), 0)),
        (('CLSID', 'pcCLSID'), 3, (3, (), [(16392, 10, None, None)], 1, 2, 4, 
0, 36, (3, 0, None, None), 0)),
        (('ProgId', 'pcProgId'), 4, (4, (), [(16392, 10, None, None)], 1, 2, 4, 
0, 40, (3, 0, None, None), 0)),
        (('Description', 'pcDescription'), 5, (5, (), [(16392, 10, None, 
None)], 1, 2, 4, 0, 44, (3, 0, None, None), 0)),
]

ICADdyAddIns_vtables_dispatch_ = 1
ICADdyAddIns_vtables_ = [
        (('Item', '__MIDL_0018', '__MIDL_0019'), 0, (0, (), [(3, 1, None, 
None), (16393, 10, None, "IID('{14F65AE1-4671-11D4-8B1A-00105A49278B}')")], 1, 
2, 4, 0, 28, (3, 0, None, None), 0)),
        (('_NewEnum', '__MIDL_0020'), -4, (-4, (), [(16397, 10, None, None)], 
1, 2, 4, 0, 32, (3, 0, None, None), 1)),
        (('Count', '__MIDL_0021'), 1, (1, (), [(16387, 10, None, None)], 1, 2, 
4, 0, 36, (3, 0, None, None), 0)),
        (('Start', '__MIDL_0022', '__MIDL_0023'), 2, (2, (), [(8, 1, None, 
None), (16393, 10, None, "IID('{14F65AE1-4671-11D4-8B1A-00105A49278B}')")], 1, 
1, 4, 0, 40, (3, 0, None, None), 0)),
        (('Stop', '__MIDL_0024'), 3, (3, (), [(9, 1, None, 
"IID('{14F65AE1-4671-11D4-8B1A-00105A49278B}')")], 1, 1, 4, 0, 44, (3, 0, None, 
None), 0)),
        (('StopAll',), 4, (4, (), [], 1, 1, 4, 0, 48, (3, 0, None, None), 0)),
]

IEnumCADdyAddIn_vtables_dispatch_ = 0
IEnumCADdyAddIn_vtables_ = [
        (('Next', 'i4Count', '__MIDL_0015', 'pi4Fetched'), 1, (1, (), [(19, 1, 
None, None), (16393, 2, None, "IID('{14F65AE1-4671-11D4-8B1A-00105A49278B}')"), 
(16403, 2, None, None)], 1, 1, 4, 0, 12, (3, 0, None, None), 0)),
        (('Skip', '__MIDL_0016'), 2, (2, (), [(19, 1, None, None)], 1, 1, 4, 0, 
16, (3, 0, None, None), 0)),
        (('Reset',), 3, (3, (), [], 1, 1, 4, 0, 20, (3, 0, None, None), 0)),
        (('Clone', '__MIDL_0017'), 4, (4, (), [(16397, 2, None, 
"IID('{14F65AE3-4671-11D4-8B1A-00105A49278B}')")], 1, 1, 4, 0, 24, (3, 0, None, 
None), 0)),
]

ISupportErrorInfo_vtables_dispatch_ = 0
ISupportErrorInfo_vtables_ = [
        (('InterfaceSupportsErrorInfo', 'riid'), 1610678272, (1610678272, (), 
[(36, 1, None, None)], 1, 1, 4, 0, 12, (3, 0, None, None), 0)),
]

RecordMap = {
}

CLSIDToClassMap = {
        '{14F65AE1-4671-11D4-8B1A-00105A49278B}' : ICADdyAddIn,
        '{D330F3E1-0F91-11D4-AC6E-00105A4925FC}' : CoCADdy,
        '{D330F3E0-0F91-11D4-AC6E-00105A4925FC}' : ICADdy,
        '{14F65AE2-4671-11D4-8B1A-00105A49278B}' : ICADdyAddIns,
        '{3F5B2591-4768-11D4-8B1C-00105A49278B}' : CADdyAddIns,
}
CLSIDToPackageMap = {}
win32com.client.CLSIDToClass.RegisterCLSIDsFromDict( CLSIDToClassMap )
VTablesToPackageMap = {}
VTablesToClassMap = {
        '{14F65AE2-4671-11D4-8B1A-00105A49278B}' : 'ICADdyAddIns',
        '{14F65AE3-4671-11D4-8B1A-00105A49278B}' : 'IEnumCADdyAddIn',
        '{D330F3E0-0F91-11D4-AC6E-00105A4925FC}' : 'ICADdy',
        '{DF0B3D60-548F-101B-8E65-08002B2BD119}' : 'ISupportErrorInfo',
        '{14F65AE1-4671-11D4-8B1A-00105A49278B}' : 'ICADdyAddIn',
}


NamesToIIDMap = {
        'ICADdyAddIn' : '{14F65AE1-4671-11D4-8B1A-00105A49278B}',
        'ICADdy' : '{D330F3E0-0F91-11D4-AC6E-00105A4925FC}',
        'ISupportErrorInfo' : '{DF0B3D60-548F-101B-8E65-08002B2BD119}',
        'IEnumCADdyAddIn' : '{14F65AE3-4671-11D4-8B1A-00105A49278B}',
        'ICADdyAddIns' : '{14F65AE2-4671-11D4-8B1A-00105A49278B}',
}

win32com.client.constants.__dicts__.append(constants.__dict__)



____________
Virus checked by G DATA AntiVirusKit
_______________________________________________
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32

Reply via email to