[python-win32] FireEvent : comtypes work but win32com fails, why?

Thomas Heller theller at ctypes.org
Wed Jun 25 17:30:36 CEST 2008


Mark Hammond schrieb:
> Thomas:
>> Mark Hammond schrieb:
>> >> > In summary, there are one big problem and one minor problem. The
>> >> > first
>> >> > is about pywin32's inability to pass FireEvent's second argument.
>> >
>> > I can't explain that :(  I've stepped through the code, and it seems
>> > we are passing a VT_VARIANT containing a VT_BYREF|VT_DISPATCH.  I'm 
>> > afraid I'm not familiar enough with comtypes to know how it is 
>> > passing that param.
>> 
>> I think that comtypes passes a VT_DISPATCH type in the DISPPARAMS
>> VARIANTARG field.
> 
> That is what I suspected - pywin32 is adding an extra level of indirection.
> When pywin32 sees VT_VARIANT, it takes it literally - it supplies a variant
> of type VT_VARIANT (ie, the variant itself holds a variant), and that
> "child" variant is what holds the real value.

I do not know where you see the VT_VARIANT.

Here is the IDL defn:

            [id(0x80010452)]
            VARIANT_BOOL FireEvent(
                            [in] BSTR bstrEventName, 
                            [in, optional] VARIANT* pvarEventObject);

and the comtypes wrapper snippet:
    DISPMETHOD([dispid(-2147417006)], VARIANT_BOOL, 'FireEvent',
               ( ['in'], BSTR, 'bstrEventName' ),
               ( ['in', 'optional'], POINTER(VARIANT), 'pvarEventObject' )),

> If I understand what you are
> saying, comtypes just supplies the variant with the real type directly in
> place (ie, a variant with a 'vartype' of VT_VARIANT isn't ever returned by
> comtypes).

Since the is a pure dispinterface, comtypes uses Invoke to call the method,
without doing any parameter conversions - it directly packs the supplied parameters
into the DISPPARAMS rgvarg array.  The 'e2' parameter in the OP's code is a
IHTMLEventObj COM pointer which is derived from IDispatch, so comtypes makes a
VT_DISPATCH variant typecode.

> Is that correct?  If so, I guess I should give that a whirl and
> hope nothing else in the test suite breaks ;)

Thats what test suites are for...

Thomas

PS: Do you know the answer to the question that I posted in the other reply to this
thread (short version: does pywin32 use IDispatchEx)?



More information about the python-win32 mailing list