Bugs item #3029949, was opened at 2010-07-15 22:09
Message generated for change (Settings changed) made by mhammond
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=551954&aid=3029949&group_id=78018
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: com
Group: None
Status: Open
>Resolution: Accepted
Priority: 5
Private: No
Submitted By: Erik Janssen (erikjanssen)
Assigned to: Nobody/Anonymous (nobody)
Summary: Type information lost in enumeration of COM objects
Initial Comment:
I am using the pywin32-214.win32-py2.7.exe distribution.
I notice type information is not always available. In the following 3-line snippet 'SearchResult' is an enumerator of objects of a certain type'.
Coding it like this everything is fine and python knows the type of f:
for i in range(0,result.SearchResults.Count):
f = result.SearchResults.Item(i)
print f.StartTime, "-", f.EndTime, f.Camera.CameraName
But in the following code, imho preffered, python complains about f being IUnknown and can't continue:
for f in result.SearchResults:
print f
print f.StartTime, "-", f.EndTime, f.Camera.CameraName
In the generated files (gencache) all information seems to be available, as in the IDL of the COM component.
I can supply lot's of additional information but I don't know what is making sense and what isn't.
----------------------------------------------------------------------
>Comment By: Mark Hammond (mhammond)
Date: 2011-04-25 11:18
Message:
I still can't see a problem with this, but we don't have test coverage for
iterators returning COM objects, so I'll leave it open until I find time to
add such an enumerator to the PyComTest com object.
Could you please tell me what "print f" displays inside the loop? First
thing I need to be sure of is whether a makepy supported object is being
used or just a "dynamc" object. It would be great if you could try this
for both the working and failing objects.
Assuming a makepy object, what *should* happen is that gen_py.py has a
special block starting with 'if specialItems["_newenum"]:'. It creates the
iterator object, but before doing so it checks the object for a method
named "Item" and assumes each element is of that type. I guess this is
failing and that we don't get the correct type from the "Item" method (even
though the IDL you posted looks fine).
Once we work out what is going on there, it may still turn out that the
iterator stuff should just get more aggressive when it gets back and
IUnknown - it should attempt to query for IDispatch and then try and use
the typeinfo to locate the correct object. This should be doable, but as
mentioned above, I'd really want test coverage before doing that.
----------------------------------------------------------------------
Comment By: Mark Hammond (mhammond)
Date: 2010-10-23 12:23
Message:
That is very strange - they look identical!
----------------------------------------------------------------------
Comment By: Erik Janssen (erikjanssen)
Date: 2010-07-19 19:32
Message:
Here is the relevant IDL, assuming that is what you refer to:
223 interface IFootageDescriptionEnumerator : IDispatch
224 {
225 [id(DISPID_NEWENUM), propget] HRESULT _NewEnum([out, retval]
IUnknown** Enumerator);
226 [id(DISPID_VALUE), propget] HRESULT Item([in] VARIANT Index, [out,
retval] IFootageDescription **FootageInfo);
227 [id(0x00000001), propget] HRESULT Count([out, retval] long * Count);
228 };
I notice that another enumarator works fine in python, it is in the IDL
declared as:
131 interface ICameraEnumerator : IDispatch{
132 [id(0xfffffffc), propget] HRESULT _NewEnum([out, retval] IUnknown
**CameraEnum);
133 [id(00000000), propget] HRESULT Item([in] int Index, [out, retval]
ICamera **CameraInfo);
134 [id(00000000), propput] HRESULT Item([in] int Index, [in] ICamera
*CameraInfo);
135 [id(0x00000001), propget] HRESULT Count([out, retval] int *Count);
Hope that helps.
----------------------------------------------------------------------
Comment By: Mark Hammond (mhammond)
Date: 2010-07-16 02:40
Message:
Does the item have a _NewEnum method? If so, how is it defined? Otherwise
I am surprised IUnknown is returned - it should behave identically to when
you call Item() manually.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=551954&aid=3029949&group_id=78018
|