
Passing by reference to an ATL COM component
Quote:
>>That makes sense since the COM method modifies the
passed argument rather
Quote:
>>than returning a value. You should be aware that while
VBScript supports
>>pass by reference, JScript does not, so you exclude any
JScript clients.
I'm adding VBScript to my application (not web page) via
the Scripting Control (VBX?) so there is no concern of
JScript.
So the question remains...
How do I pass a parameter to a COM control and have the
modified parameter passed back up to the calling script?
This *must* be possible!
Quote:
>-----Original Message-----
>> Well the article you pointed me to seems to be
addressing
>> my problem, but it still doesn't work :(
>> Here is the error I get now:
>> Error: Wrong number of arguments or invalid property
>> assignment: 'UOTCtrl.Connect', ; in line 5
>> I tried changing the IDL from [out,retval] to [out] and
>> that seemed to eliminate the error message, but then
we're
>> back to having the change made in 'Connect' not make it
>> back up to to VBScript.
>That makes sense since the COM method modifies the passed
argument rather
>than returning a value. You should be aware that while
VBScript supports
>pass by reference, JScript does not, so you exclude any
JScript clients.
>> Here's my VBScript function:
>> Function test(xx)
>> Set UOTCtrl = CreateObject("UOTCtrl.Application")
>> hSession=123
>> UOTCtrl.Connect(hSession)
>This should be:
> UOTCtrl.Connect hSession 'preferred syntax
>or
> Call UOTCtrl.Connect(hSession) 'OK but unnecessary
>When calling a COM method that does not return a value
(in VBScript
>terminology, a Sub as opposed to a Function that does
return a value), ()s
Quote:
>are not used to enclose the argument list unless you
explicitly use the Call
Quote:
>statement.
>In the case of calling a method that takes only a single
argument, using the
>otherwise unnecessary ()s around the single argument
turns the argument into
Quote:
>an expression, the value of which is passed to the
method. The method
>expects a byref argument but ends up modifying the
temporary memory holding
Quote:
>the value of the expression rather than the memory
representing the client
Quote:
>variable within the expression.
>If your COM method had expected 2 arguments, then
> UOTCtrl.Connect(hSession, arg2)
>would have thrown a runtime error of "cannot use
parentheses when calling a
Quote:
>Sub" and the problem would have been more obvious...
>--
>Michael Harris
>Microsoft.MVP.Scripting
>Seattle WA US
>.