COM / Variants / VT_BOOL
aleaxit at yahoo.com
Thu Dec 28 08:56:31 EST 2000
"Mark Hammond" <MarkH at ActiveState.com> wrote in message
news:3A4B2F8C.4000909 at ActiveState.com...
> Alex Martelli wrote:
> > *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).
> Quite possibly it would. If win32com had type information, it would
> have dont the right thing.
True -- because then calls would always go on the IDispatch side of
things; I had not considered this.
> > 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
> Without type info, the parser should call VariantChangeType() to get a
> valid VT_BOOL back. So really the parser is at fault (or the client for
> ignoring it)
Except that we were using the custom-side of things (from C++),
not the dispatch-side, and therefore passing, not a 'variant',
but a VARIANT_BOOL directly. VARIANT_BOOL is a typedef for some
integral type (short int, I think), so, C++ happily accepts a
value of 1 and does no transformation on it. Not sure if the
VariantChangeType is being done on Xerces' side (I guess they'll
be using a normal CreateStdDispatch to make the dispatch-side
from the custom-side, like everybody else, so the changetype
should be happening IF a call comes in from the custom-side).
> > *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.
> Also, a feature of the pythoncom type conversion means that you can say:
> true = 1==1
> false = 1==0
> And passing these variables (or the expression as a literal) _will_
> force a VT_BOOL of the correct type.
...if makepy, or whatever, has given Python the needed typelibrary
information, that is; or, failing that, the server is implementing
the needed change-type correctly.
There may be one chance in a hundred that any given problem comes
from a combination of these safeguards all failing at once... but,
using '-1' to indicate 'true' is a cheap enough price to pay for
that 1%-risk of disaster insurance, I think:-).
More information about the Python-list