How to increase PythonWin v2.0: COM browser limits?

Ben Hutchings ben.hutchings at roundpoint.com
Tue Mar 20 17:24:59 EST 2001


I wrote:

> The wrapper for COM enumerators, in true Pythonic style, does not
> check the size of the collection in advance, but attempts to read
> items until this yields an error.  I think that the category
> enumerator implementation is reporting the no-more-items error in the
> wrong way (returning E_OUTOFMEMORY rather than S_FALSE), so the
> wrapper does not translate it into an IndexError exception which
> would cause the loop to terminate successfully.  OLEView probably
> just doesn't check for the error but displays what it already got.

Let me revise that:

A Python iterator for a COM 'container' is an instance of
win32com.client.util.Enumerator, which wraps a PyIEnumVARIANT object
that in turn wraps an IEnumVARIANT interface pointer obtained from the
container.  When an IEnumVARIANT user requests more items than there
are left, the implementation should return any items that are left,
with a status code of S_FALSE (not an error code).

In the case of iteration, Enumerator will request only 1 item each
time.  PyIEnumVARIANT's wrapper function returns a list of items,
which at the end of iteration will have length 0.  Enumerator checks
for this case and throws an IndexError when it occurs, which is the
normal way for iteration to end.  Unfortunately it appears that this
specific implementation of IEnumVARIANT returns a status code of
E_OUTOFMEMORY (an error code), which PyIEnumVARIANT turns into a
win32types.com_error exception.

OLEView probably treats this error in the same way as a normal end
of enumeration, and displays the results it already obtained.

-- 
Any opinions expressed are my own and not necessarily those of Roundpoint.



More information about the Python-list mailing list