COM / Variants / VT_BOOL

Alex Martelli aleaxit at yahoo.com
Fri Dec 22 03:20:31 EST 2000


"Stefan Migowsky" <smigowsky at dspace.de> wrote in message
news:mailman.977467384.30398.python-list at python.org...
> You do not need to create a VARIANT ! The win32com library automatically
> converts almost all Python objects to the corresponding VARIANT type.
> Since VT_BOOL is just an int which is transmitted through the COM channel
> you can use the simple Python 1 or 0, e.g.
> server = win23com.client.Dynamic("XXX")
>
> server.Enabled = 1 # Set to true
> server.Enabled = 0 # Set to false

*Almost* right... but not *quite*, and we hit this specific problem
quite recently (we weren't driving with Python, but I think that
would have made no difference).

VARIANT_BOOL (the content of VARIANT's discriminated union when
its type-tag is VT_BOOL) is defined as a 16-bit value that is
either 0 ('false') or 0xFFFF ('true'); other values are, it seems,
"not permitted".  Any 'sensible' server would 'of course' take
any non-zero here as 'true'... but we just found out you cannot
*COUNT* on that.

Setting the property .ValidateOnParse of the Xerces XML parser
(originally from IBM, now, I believe, from Apache), in its COM
setting, to 0 *or* 1, still keeps the parser non-validating; you
HAVE to set it to -1 or 65535 to make the parser a validating
one.  I have not checked the behavior of Microsoft's MSXML,
which the packaging of Xerces as a COM server is apparently
intended to generally mimic; but, anyway, I suspect the Xerces
team will not acknowledge this as a 'bug', whatever MSXML does
in the (non-documented, non-supported) case that one sets this
'boolean' property to a non-permitted value -- and, formally,
they would, I guess, be right.  I have not checked Xerces'
sources to confirm this, but I guess that somewhere they're
testing the property's value for "== VARIANT_TRUE".

*Most* COM servers will happily accept 'server.BoolProp = 1'
as setting the property to 'true', but, I suggest, don't count
on that; use 'server.BoolProp = -1' and you might be safer.


Alex






More information about the Python-list mailing list