That is strange - the problem is that the resulting COM object is returning an IUnknown rather than an IDispatch. A work around should be to say:
c = cams[0] c = win32com.client.Dispatch(c) or possibly: c = win32com.client.Dispatch(c.QueryInterface(pythoncom.IID_IDispatch)) I think we could also argue this is a bug in win32com - it should try and QI any IUnknown objects - but changing this might break existing code... Mark -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Jason Ferrara Sent: Thursday, 5 July 2007 12:30 AM To: python-win32@python.org Subject: [python-win32] issues with win32com constants and static/dynamicdispatch I'm trying to use a COM library from python. If I use dynamic dispatch, the com objects all behave correctly, but the constants defined in the COM library don't show up. If I use static dispatch, the constants show up, but COM objects returned by calls into the COM library seem broken. As example, starting with dynamic dispatch Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import win32com.client >>> mi=win32com.client.Dispatch("MIDLIBCom.MIDLib") >>> cams=mi.OpenCameras("C:\Program Files\Micron Imaging\sensor_data") >>> c=cams[0] >>> print c <COMObject OpenCameras> >>> print c.productName Micron Imaging DEMO2 So far everything is fine, but now... >>> print win32com.client.constants.MI_BAYER_8 Traceback (most recent call last): File "<stdin>", line 1, in <module> File "C:\Python25\Lib\site-packages\win32com\client\__init__.py", line 168, in __getattr__ raise AttributeError, a AttributeError: MI_BAYER_8 This is no good. So now I try static dispatch Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import win32com.client >>> mi=win32com.client.gencache.EnsureDispatch("MIDLIBCom.MIDLib") >>> print win32com.client.constants.MI_BAYER_8 1 Things are looking better, but now... >>> cams=mi.OpenCameras("C:\Program Files\Micron Imaging\sensor_data") >>> c=cams[0] >>> print c <PyIUnknown at 0xac640c with obj at 0xf0d808> >>> print c.productName Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: 'PyIUnknown' object has no attribute 'productName' So whats going on here? What am I doing wrong? Thanks - J
_______________________________________________ Python-win32 mailing list Python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32