#495 Type information lost in enumeration of COM objects

open-accepted
nobody
com (105)
5
2011-04-25
2010-07-15
No

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.

Discussion

  • Mark Hammond

    Mark Hammond - 2010-07-15

    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.

     
  • Erik Janssen

    Erik Janssen - 2010-07-19

    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.

     
  • Mark Hammond

    Mark Hammond - 2010-10-23

    That is very strange - they look identical!

     
  • Mark Hammond

    Mark Hammond - 2011-04-25

    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.

     
  • Mark Hammond

    Mark Hammond - 2011-04-25
    • status: open --> open-accepted
     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks