Re: COM:- passing a variant by reference...

From: Ashok K Kumar (AshokKKumar_at_discussions.microsoft.com)
Date: 12/02/04


Date: Thu, 2 Dec 2004 23:00:19 +0530

You are set a wrong values to the Variant. VT_I4 | VT_BYREF means that the
variant should a pointer to a long value and the data member should "plVal"
and not "lVal".

By the way I thought you want assign a value to a variable that is passed by
ref to your COM component. For that you just have to clear the value held by
the variant pointer and set the new value like below.

VariantClear(vVal);
vVal->vt = VT_I4; //you should not use BYREF here, since you are assigning a
value not a reference.
vVal->lVal = 10; //or some number

-- 
------------------------------
Ashok K Kumar
------------------------------
"Thomas Sedlaczek" <ThomasSedlaczek@discussions.microsoft.com> wrote in
message news:1490F4CA-C1DB-4831-AFA4-9AEF8C09FC28@microsoft.com...
> Hello,
>
> How can I pass a variant type by reference from a VBscript to my COM
> dispatched function? I have tried the code below but assigning a new value
> does not change the value of the referenced VBscript variable. What I am
> doing wrong? Where can I find an example?
>
> Best regards,
> Thomas
>
> DISP_FUNCTION(MyScriptObject, "FunctionByReference", FunctionByReference,
> VT_EMPTY, VTS_VARIANT) // VTS_PVARIANT delivers also a type mismatch.
>
> void MyScriptObject::FunctionByReference(VARIANT* vVal)
> {
>    vVal->vt = VT_I4|VT_BYREF;
>    vVal->lVal = ...; // assign new value
> }
>


Relevant Pages

  • Re: How to casting to VARIANT*
    ... > The second parameter to be passed is a range 'object'. ... but I wonder why MSWORD is designed this way. ... in there that just take a plain VARIANT. ... optional are also passed by pointer. ...
    (microsoft.public.vc.atl)
  • Re: Pass arguments with IDispatch.Invoke
    ... Marshal.StructureToPtr(v, LibraryVersion, true); ... I'm getting pointer to the structure from C, ... Alexander Nickolov wrote: ... The problem is a VARIANT does ...
    (microsoft.public.vc.atl)
  • Re: Accessing binary field in a Microsoft Access database table
    ... mismatched data types. ... There is absolutely no guarantee that the variant contains a long. ... The variants should be used _BY VALUE_ not by pointer. ... pointer (reference) to the variant, ...
    (microsoft.public.data.ado)
  • Re: How to casting to VARIANT*
    ... Microsoft MVP, MCSD ... but I wonder why MSWORD is designed this way. ... > in there that just take a plain VARIANT. ... > optional are also passed by pointer. ...
    (microsoft.public.vc.atl)
  • Re: Variants
    ... For UDTs, arrays, objects etc, a ... Variant always contains a pointer. ... But strings in Variants are pointers, ...
    (microsoft.public.vb.general.discussion)