Re: How to casting to VARIANT*

From: Simon Trew (noneofyour_at_business.guv)
Date: 04/30/04


Date: Fri, 30 Apr 2004 14:54:25 +0100


"Sankalp" <sankalp_reddy@hotmail.com> wrote in message
news:O23XrEqLEHA.1340@TK2MSFTNGP12.phx.gbl...
> Hi,
> Thanks a lot Simon. That worked.
>
> The second parameter to be passed is a range 'object'. The fn. prototype
is
> as follows:
> virtual HRESULT __stdcall Add (
> /*[in]*/ BSTR Name,
> /*[in]*/ VARIANT * Range,
> /*[out,retval]*/ struct Bookmark * * prop ) = 0;
> Is'nt this how objects are passed around (rather than make another copy of
> the object)?

Perhaps I'm mistaken, but it's not usual to pass an IN parameter as a
pointer. I checked the Word type library and it is indeed so; your code is
correct, but I wonder why MSWORD is designed this way. (Perhaps historical?)
I just looked at MSXML by way of comparison, and there are plenty of methods
in there that just take a plain VARIANT.

The Range parameter is marked as Optional, but I don't think this can make a
difference; other parameters in other methods that are not marked as
optional are also passed by pointer. An missing optional variant is usually
passed by setting its type to VT_EMPTY, anyway.

Copying is not really an issue. The server (MSWORD) is out-of-process and so
the object has to be marshalled (copied) across the process boundary anyway.
If I understand it correctly, marking the parameter as [in] means it won't
be marshalled back at the end, so it's not as if you can get any information
back through it.

Even in the in-process case, a VARIANT is only 16 bytes[1], so it's hardly
expensive to make a shallow copy.

S.

[1] On a 32-bit platform. On a 64-bit platform it might be wider, but I
doubt it, because even then a pointer is no wider than a double.



Relevant Pages

  • 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: 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: Variants
    ... For UDTs, arrays, objects etc, a ... Variant always contains a pointer. ... But strings in Variants are pointers, ...
    (microsoft.public.vb.general.discussion)
  • Re: want to resize window in vbs
    ... variant using the varptr function. ... UserWrap.MessageBoxA Null, CStr, "From DynaWrap Object", 3 ... i get "0" for the pointer. ... > for byref parameters, BUT ONLY STRING parameters. ...
    (microsoft.public.scripting.wsh)
  • Re: Simulating VB Nothing variant in Delphi
    ... IDispatchshould be used instead of Unassigned (some ActiveX components ... the MSWord variable causes the OLE Automation Object that was created to ... The Unassigned function returns a variant with VType varEmpty, ... whereas the Nothing variant in VBA is a variant with VType varDispatch. ...
    (borland.public.delphi.database.ado)

Loading