[python-win32] issues with win32com constants and static/dynamicdispatch
Jason Ferrara
jason.ferrara at jacquette.com
Thu Jul 5 02:03:40 CEST 2007
c = win32com.client.Dispatch(c.QueryInterface(pythoncom.IID_IDispatch))
works. Thanks!
FYI, c=win32com.client.Dispatch(c) does not.
>>> c=win32com.client.Dispatch(c)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python25\Lib\site-packages\win32com\client\__init__.py",
line 96, in Dispatch
return __WrapDispatch(dispatch, userName, resultCLSID, typeinfo,
UnicodeToString, clsctx)
File "C:\Python25\Lib\site-packages\win32com\client\__init__.py",
line 44, in __WrapDispatch
return dynamic.Dispatch(dispatch, userName, WrapperClass,
typeinfo, UnicodeToString=UnicodeToString,clsctx=clsctx)
File "C:\Python25\lib\site-packages\win32com\client\dynamic.py",
line 111, in Dispatch
typeinfo = IDispatch.GetTypeInfo()
AttributeError: 'PyIUnknown' object has no attribute 'GetTypeInfo'
On Jul 4, 2007, at 7:03 PM, Mark Hammond wrote:
> 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: python-win32-bounces at python.org [mailto:python-win32-
> bounces at python.org]On Behalf Of Jason Ferrara
> Sent: Thursday, 5 July 2007 12:30 AM
> To: python-win32 at 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
>
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/python-win32/attachments/20070704/498a3d2b/attachment-0001.html
More information about the Python-win32
mailing list