Discussion:
OCX returning a variable number of variants ?
(too old to reply)
R.Wieser
2022-01-07 17:19:50 UTC
Permalink
Hello all,

I've written a method which, using VBScript, accepts a variable number of
arguments, which is described in the IDL as follows :

[vararg] HRESULT Put([in] SAFEARRAY(VARIANT) aList);

But now I want to do the reverse. Call a method with a variable number of
variants and have the called method fill them in.

To be clear about it :

1) I do /not/ want to return a fixed number of results.

2) I do /not/ want the method to return an array and than pick my results
outof that array.

IOW, I want to be able to use :

Put(Var1,Var2,Var3, ...) '<-- This already works

and than :

Get(Var1,Var2,Var3, ...)

Question : is what I'm after at all possible ?

Regards,
Rudy Wieser
R.Wieser
2022-01-07 18:30:57 UTC
Permalink
Post by R.Wieser
But now I want to do the reverse. Call a method with a variable number
of variants and have the called method fill them in.
The answer ofcourse popped into my mind mere minutes after having posted the
question :

[vararg] HRESULT Get([in,out] SAFEARRAY(VARIANT)* aList);

The called method does show the contents of the supplied variants.


But I've ran into the next problem : when I now use SafeArrayPutElement (to
return some values) I do not see it back in the variant(s) I supplied to the
method.

Most likely this is because the contents of the SafeArray are ByRef, and (I
think) I'm putting the data into the array ByVal - and thus not into the
supplied (ByRef) variant(s).

Hmmm ... Anyone have an idea for me ?

Regards,
Rudy Wieser
JJ
2022-01-08 06:09:50 UTC
Permalink
Post by R.Wieser
Hello all,
I've written a method which, using VBScript, accepts a variable number of
[vararg] HRESULT Put([in] SAFEARRAY(VARIANT) aList);
But now I want to do the reverse. Call a method with a variable number of
variants and have the called method fill them in.
1) I do /not/ want to return a fixed number of results.
2) I do /not/ want the method to return an array and than pick my results
outof that array.
Put(Var1,Var2,Var3, ...) '<-- This already works
Get(Var1,Var2,Var3, ...)
Question : is what I'm after at all possible ?
Regards,
Rudy Wieser
I haven't seen any programming language whose function can actually return
multiple values without placing them in some kind of a container or an
interface.
R.Wieser
2022-01-08 08:58:00 UTC
Permalink
JJ,
Post by JJ
I haven't seen any programming language whose function can actually
return multiple values without placing them in some kind of a container
or an interface.
:-) As you might know I mostly write Assembly. In it returning multiple
results is as easy as supplying pointers to the respective "variables"
(read: memory areas) to a function.

Or, as it is called in several programming languages, providing the argument
"by reference" (instead of the more common "by value").

Ofcourse, there has been a great push to banish "by reference" arguments, as
its is much harder to prove that programs which use them do not have
un-intended side effects (at least, that is what I've been told by someone
who studied for it).


But as a quick test I just tried this method :

HRESULT GetTest(out] variant* var1,[out] variant* var2);

and it works fine.

IOW, thats the second language you now know which can do it. p :-)

-- but --

It turns out I made a simple mistake, making it /look/ as if my OCX didn't
work : while I provided three different variables I displayed the first one
twice followed by the third one. And as I test-stored my result in the
second variable ... :-|

Regards,
Rudy Wieser
JJ
2022-01-09 06:33:50 UTC
Permalink
Post by R.Wieser
HRESULT GetTest(out] variant* var1,[out] variant* var2);
and it works fine.
IOW, thats the second language you now know which can do it. p :-)
Functions' out arguments are just pointers to a buffer for the function to
fill. They're not the function's return value. That function's return value
is the HRESULT. They're all function results. But only one is the function
return return value.
R.Wieser
2022-01-09 08:02:51 UTC
Permalink
JJ,
Post by JJ
Functions' out arguments are just pointers to a buffer for the function
to fill.
Indeed. And that is what I was asking for : "and have the called method
*fill them in*" (bolding mine).

Regards,
Rudy Wieser

Loading...