Hello all,

I want to bring VB scripting support to my MFC aplication. Therfore I need
to provide COM interface to my C++ functions. Now the problem seams that VB
script does not provide reference types or pointers. But how can I have a
function in VB-script that modifies more than one variable and retuns it to
the calling function?

Like C++ function:

void MyFunction(int iValue, int &iWillModifyA, long & lWillModifyB);

How can I express this in VB-script?

Best Regards
Thomas

Re: VB-script multiple return or reference type? by mr

mr
Wed Dec 01 12:02:46 CST 2004

hi Thomas,

I don't know anything about c++, but you probably know that vbScript
variables are all variants. And all the vbs calling sequences are "byRef"
variants.

You should be able to get it to work if you set up your ole interface to
accept byref variants. That is, vbs will pass the address of a variant back
to you.

As far as determining what you get, i.e., a string, integer, long, etc
stored in the variant, you are going to have to "pick it apart". There are
functions in vb to do this, whereas c++ programmers may be doing it "the
hard way", (i.e., using the variant typedef, and the vt_I2, vt_I4,,, variant
type constants) to determine what is stored in the variant.

If this is not good enough, then wait-a-bit, and a better qualified expert
will come along and answer your question for you.

cheers, jw


"Thomas Sedlaczek" <ThomasSedlaczek@discussions.microsoft.com> wrote in
message news:27E30A94-624C-4E2B-B029-63412E613760@microsoft.com...
> Hello all,
>
> I want to bring VB scripting support to my MFC aplication. Therfore I need
> to provide COM interface to my C++ functions. Now the problem seams that
VB
> script does not provide reference types or pointers. But how can I have a
> function in VB-script that modifies more than one variable and retuns it
to
> the calling function?
>
> Like C++ function:
>
> void MyFunction(int iValue, int &iWillModifyA, long & lWillModifyB);
>
> How can I express this in VB-script?
>
> Best Regards
> Thomas
>



Re: VB-script multiple return or reference type? by Torgeir

Torgeir
Wed Dec 01 11:58:04 CST 2004

Thomas Sedlaczek wrote:

> Hello all,
>
> I want to bring VB scripting support to my MFC aplication. Therfore I need
> to provide COM interface to my C++ functions. Now the problem seams that VB
> script does not provide reference types or pointers. But how can I have a
> function in VB-script that modifies more than one variable and retuns it to
> the calling function?
Hi

You may find something here:

Building COM Components That Take Full Advantage of Visual Basic and
Scripting
http://msdn.microsoft.com/library/techart/msdn_vbscriptcom.htm


--
torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of
the 1328 page Scripting Guide:
http://www.microsoft.com/technet/scriptcenter/default.mspx

Re: VB-script multiple return or reference type? by ThomasSedlaczek

ThomasSedlaczek
Wed Dec 01 14:41:16 CST 2004

Hi jw,

thank you for your detailed answer! :-)

I should have been aware the fact that Variant is by default a reference
type. But somehow I forgot it though all this C++ stuff. I think the reason
why my sample app didnt work lies on the C++ side. So I should be able to
solve the rest my self.

Thank you for your help and have a bug-free day! :o)

Best regards,
Thomas

"mr unreliable" wrote:

> hi Thomas,
>
> I don't know anything about c++, but you probably know that vbScript
> variables are all variants. And all the vbs calling sequences are "byRef"
> variants.
>
> You should be able to get it to work if you set up your ole interface to
> accept byref variants. That is, vbs will pass the address of a variant back
> to you.
>
> As far as determining what you get, i.e., a string, integer, long, etc
> stored in the variant, you are going to have to "pick it apart". There are
> functions in vb to do this, whereas c++ programmers may be doing it "the
> hard way", (i.e., using the variant typedef, and the vt_I2, vt_I4,,, variant
> type constants) to determine what is stored in the variant.
>
> If this is not good enough, then wait-a-bit, and a better qualified expert
> will come along and answer your question for you.
>
> cheers, jw
>
>
> "Thomas Sedlaczek" <ThomasSedlaczek@discussions.microsoft.com> wrote in
> message news:27E30A94-624C-4E2B-B029-63412E613760@microsoft.com...
> > Hello all,
> >
> > I want to bring VB scripting support to my MFC aplication. Therfore I need
> > to provide COM interface to my C++ functions. Now the problem seams that
> VB
> > script does not provide reference types or pointers. But how can I have a
> > function in VB-script that modifies more than one variable and retuns it
> to
> > the calling function?
> >
> > Like C++ function:
> >
> > void MyFunction(int iValue, int &iWillModifyA, long & lWillModifyB);
> >
> > How can I express this in VB-script?
> >
> > Best Regards
> > Thomas
> >
>
>
>

Re: VB-script multiple return or reference type? by ThomasSedlaczek

ThomasSedlaczek
Wed Dec 01 14:43:03 CST 2004

Hello Torgeir,

Thank your for this link. Is very interresting! :o)

Regards from sunny south Wales,
Thomas

"Torgeir Bakken (MVP)" wrote:

> Thomas Sedlaczek wrote:
>
> > Hello all,
> >
> > I want to bring VB scripting support to my MFC aplication. Therfore I need
> > to provide COM interface to my C++ functions. Now the problem seams that VB
> > script does not provide reference types or pointers. But how can I have a
> > function in VB-script that modifies more than one variable and retuns it to
> > the calling function?
> Hi
>
> You may find something here:
>
> Building COM Components That Take Full Advantage of Visual Basic and
> Scripting
> http://msdn.microsoft.com/library/techart/msdn_vbscriptcom.htm
>
>
> --
> torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
> Administration scripting examples and an ONLINE version of
> the 1328 page Scripting Guide:
> http://www.microsoft.com/technet/scriptcenter/default.mspx
>

Re: VB-script multiple return or reference type? by Michael

Michael
Wed Dec 01 20:27:06 CST 2004

> I want to bring VB scripting support to my MFC aplication. Therfore I
> need to provide COM interface to my C++ functions. Now the problem
> seams that VB script does not provide reference types or pointers.
> But how can I have a function in VB-script that modifies more than
> one variable and retuns it to the calling function?
>
> Like C++ function:
>
> void MyFunction(int iValue, int &iWillModifyA, long & lWillModifyB);
>
> How can I express this in VB-script?

PRB: Passing Parameters By Reference to a VC COM Object
http://support.microsoft.com/default.aspx?kbid=197957

Has C++ syntax examples...

--
Michael Harris
Microsoft MVP Scripting



Re: VB-script multiple return or reference type? by ThomasSedlaczek

ThomasSedlaczek
Fri Dec 03 05:13:02 CST 2004

Hello Michael,

I have it ! ;o)

The problem was in the VBscript. Parentheses around fuction parameters cause
an argument to be passed by value. Even if the routine is expecting the
parameter to be passed by reference. Thank you for your help!!! :-)

Have a nice day!
Thomas

So the script must look like this:
Dim value
value=5
ShowValue(value) 'shows that value is 5
FunctionByReference value 'do not use parentheses!
ShowValue(value) 'shows that value is 123 ;-)

The function must look like this:
void MyScriptObject::FunctionByReference(VARIANT* pvVal)
{
VariantClear(pvVal);
pvVal->vt = VT_I4;
pvVal->lVal = 123; // assign new value
}

The dispatch map must looks like:
BEGIN_DISPATCH_MAP(MyScriptObject, CCmdTarget)
DISP_FUNCTION(MyScriptObject, "ShowValue",
ShowValue, VT_EMPTY, VTS_I4)
DISP_FUNCTION(MyScriptObject, "FunctionByReference",
FunctionByReference, VT_EMPTY, VTS_PVARIANT)
END_DISPATCH_MAP()