VB, WSH and [out] BSTR * 
Author Message
 VB, WSH and [out] BSTR *

I don't much about IDL or C++, but if you want to pass an argument from a script
client to a COM object's method and have that argument modified by the method
and returned to the script client, you'll have to define it (in the COM object)
as a Variant argument.

In the VB client you're passing a string to a string argument (no coercion
needed).

In the VBScript client you want to pass a variant ByRef to a string argument but
the default implementation of IDispatch won't coerce (it will only coerce a
variant passed ByVal to a non-variant argument).  Enclosing it in ()'s forced it
to be passed ByVal which is why the call "works" (i.e., the ByVal variant will
be coerced to a string argument) but you don't get the modified value back.

--
Michael Harris


| I stumped on this one, if anyone could help me out, it would be much
| appreciated.
|
| using:
| VB5
| VC++6
| NT Server 4 (opt pak 4)
|
|
|
| if I call this sub from vb
|
|
|     Private Sub Command1_Click()
|         Dim o As New COMPONENTLib.Jack
|         Dim s As String
|         o.Useless s
|         MsgBox s
|     End Sub
|
|
| which calls method o.Useless()
| described in IDL as
|
|
|     [id(1), helpstring("method Useless")] HRESULT Useless( [out] BSTR *
| pbstr);
|
|
| I get the correct value to the MsgBox of the Command1_Click() method
|
|
| BUT...
|
|
| when I try to call the function from a WSH script like this
|
|
|     Dim oj , outParam
|     Set oj=Wscript.CreateObject("Component.Jack")
|     oj.Useless (outParam)
|     MsgBox outParam
|
|
| the MsgBox is empty
|
|



Fri, 08 Feb 2002 03:00:00 GMT  
 VB, WSH and [out] BSTR *
thanks,
I changed the BSTR* to a VARIANT* , recompiled, and tested it and now it
works as expected.

It didn't seem right when I was calling the sub like a function, but it was
one way to get it to execute (though, not the way I had hoped).

        Dim oj , outParam
        Set oj=Wscript.CreateObject("Component.Jack")
?>> oj.Useless (outParam)
        MsgBox outParam

Quote:

>I don't much about IDL or C++, but if you want to pass an argument from a
script
>client to a COM object's method and have that argument modified by the
method
>and returned to the script client, you'll have to define it (in the COM
object)
>as a Variant argument.

>In the VB client you're passing a string to a string argument (no coercion
>needed).

>In the VBScript client you want to pass a variant ByRef to a string
argument but
>the default implementation of IDispatch won't coerce (it will only coerce a
>variant passed ByVal to a non-variant argument).  Enclosing it in ()'s
forced it
>to be passed ByVal which is why the call "works" (i.e., the ByVal variant
will
>be coerced to a string argument) but you don't get the modified value back.

>--
>Michael Harris



Fri, 08 Feb 2002 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Session Variable Time-outs

2. WSH and VB class: WSH error by pressing ctrl-C

3. xmldoc.xml & string = bstr / Problem with encoding

4. Garbage writing BSTR to text file

5. Converting Javascript strings to C++ BSTR* ???

6. BSTR type

7. Passing SAFEARRAYS of BSTR and int to a VBScript

8. xmldoc.xml & string = bstr / Problem with encoding

9. C++ ActiveX Property returns VARIANT Array of BSTR for VBScript or JavaScript

10. BSTR as parameter of method

11. Passing BSTR * as an argument

12. com variant bstr array

 

 
Powered by phpBB® Forum Software