Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Returning an array of double's: which COM/OLE type is better?

0 views
Skip to first unread message

Giovanni Dicanio

unread,
Oct 12, 2009, 4:42:58 AM10/12/09
to

Suppose we are developing a COM server exposing an interface with a method
to return an array of double's to the caller.

I think that there are four options to define this output parameter (which
is an array of double's):

1. SAFEARRAY of double's
2. SAFEARRAY of VARIANT's (each VARIANT being a double)
3. VARIANT which is a SAFEARRAY of double's
4. VARIANT which is a SAFEARRAY of VARIANT's (each VARIANT being a double)

Is there any rule or guideline to follow to choose the right option?
Is there any particular advantage in choosing one respect to others?

Thanks,
Giovanni


Igor Tandetnik

unread,
Oct 12, 2009, 8:07:55 AM10/12/09
to
Giovanni Dicanio wrote:
> Suppose we are developing a COM server exposing an interface with a
> method to return an array of double's to the caller.
>
> I think that there are four options to define this output parameter
> (which is an array of double's):
>
> 1. SAFEARRAY of double's
> 2. SAFEARRAY of VARIANT's (each VARIANT being a double)
> 3. VARIANT which is a SAFEARRAY of double's
> 4. VARIANT which is a SAFEARRAY of VARIANT's (each VARIANT being a
> double)
>
> Is there any rule or guideline to follow to choose the right option?

KISS (http://simple.wikipedia.org/wiki/K.I.S.S.)

Most of the time, I'd go with #1, as expressing my intent most directly. However, if your component has to be used from VBScript, then go with #2 - VBScript can only handle a safearray of variants.
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not necessarily a good idea. It is hard to be sure where they are going to land, and it could be dangerous sitting under them as they fly overhead. -- RFC 1925

Giovanni Dicanio

unread,
Oct 12, 2009, 10:59:25 AM10/12/09
to

"Igor Tandetnik" <itand...@mvps.org> ha scritto nel messaggio
news:u6fOkSzS...@TK2MSFTNGP04.phx.gbl...

> KISS (http://simple.wikipedia.org/wiki/K.I.S.S.)
>
> Most of the time, I'd go with #1, as expressing my intent most directly.
> However, if your component has to be used from VBScript, then go with #2 -
> VBScript can only handle a safearray of variants.

Thank you,
Giovanni

Brian Muth

unread,
Oct 13, 2009, 12:36:57 PM10/13/09
to
Giovanni, I concur with Igor. If you want it scriptable, then use either 2
or 4 (my own preference is 4). Otherwise, I'd use 1.

Brian

Giovanni Dicanio

unread,
Oct 13, 2009, 1:13:22 PM10/13/09
to

"Brian Muth" <bm...@mvps.org> ha scritto nel messaggio
news:45698A77-F3B4-494C...@microsoft.com...


> Giovanni, I concur with Igor. If you want it scriptable, then use either 2
> or 4 (my own preference is 4). Otherwise, I'd use 1.

Thanks Brian.

In case of scriptable component, why do you prefer 4 instead of 2?

Is the intent more clear when using a SAFEARRAY (2) instead of a VARIANT
which is a SAFEARRAY (4) ?
Or, in case of scriptable component, would you just use VARIANT's everywhere
(e.g. also for scalar integer type, etc.)?

Using VARIANT's seems to me like giving a more "dynamic" look to the
component interface, but IMHO I would prefer making the intent more clear,
so using VARIANT's as few as possible.

Thanks,
Giovanni

Jim Barry

unread,
Oct 14, 2009, 2:01:52 PM10/14/09
to
Giovanni Dicanio wrote:
> Is the intent more clear when using a SAFEARRAY (2) instead of a VARIANT
> which is a SAFEARRAY (4) ?
> Or, in case of scriptable component, would you just use VARIANT's
> everywhere (e.g. also for scalar integer type, etc.)?

Scripting languages access COM objects through IDispatch, so each
non-VARIANT parameter or return value is automatically wrapped in a
VARIANT. It only makes any difference to clients that access custom
interfaces (or dual interfaces via vtable methods).

- Jim

Giovanni Dicanio

unread,
Oct 14, 2009, 5:13:21 PM10/14/09
to
"Jim Barry" <j...@mvps.org> ha scritto nel messaggio
news:#5fLrhPT...@TK2MSFTNGP05.phx.gbl...

> Scripting languages access COM objects through IDispatch, so each
> non-VARIANT parameter or return value is automatically wrapped in a
> VARIANT. It only makes any difference to clients that access custom
> interfaces (or dual interfaces via vtable methods).

Thanks Jim!

Giovanni

0 new messages