Re: VBS gets empty string

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Alexander Nickolov (agnickolov_at_mvps.org)
Date: 07/28/04


Date: Wed, 28 Jul 2004 10:00:01 -0700

VBScript can only deal with VARIANTs. It cannot get your
BSTR back. Also, you cannot have [out] arguments in
Automation (and VBScript laughs at them all the same).
Change it to [in, out] VARIANT*. Even simpler, why don't
you use [out, retval]? Then you can stick with returning
a BSTR and your server code won't change, only your
script code. As for [in, out], there is a lengthy thread in
this group detailing just that topic, I suggest you give it a
look:

How to return string through output VARIANT from C++
COM object

-- 
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD
email: agnickolov@mvps.org
MVP VC FAQ: http://www.mvps.org/vcfaq
=====================================
"Eran" <even_e@netvision.net.il> wrote in message
news:e1Yh2QKdEHA.556@tk2msftngp13.phx.gbl...
> Hi,
>
> I need help for the following issue. I have a COM server in C++ and client
> in VBS. in some reason, the VBS gets empty string from COM.
>
> the implemintation is as follows:
>
> [COM]
> [id(4), helpstring("method RetString")] HRESULT ReturnString([out] BSTR
> *RetString);
>
>
> STDMETHODIMP CETS_Interface::ReturnString(BSTR *RetString)
> {
>
>  char MyString[10] = "temp";
>  *RetString = A2BSTR(MyString);
>  return (*RetString != NULL) ? S_OK : E_OUTOFMEMORY;
> }
>
>
> [VBS]
>
>  ' ETS_Interface of "ETS.ETS_Interface.1"
> ' ETS_Interface Class
> Set objETS_Interface = CreateObject("ETS.ETS_Interface")
>
> Dim mystring
>
>  objETS_Interface.RetString(mystring)
> MsgBox(mystring) ' in some reason, I mystring is empty here.
>
>


Relevant Pages

  • Re: How to pass variant (array of bytes) to winsock.ocx
    ... Well, like I said in my first post, the GetData seems to work fine when I ... define the variant as a BSTR, ... the variants to retrieve the data as a array of bytes, ...
    (microsoft.public.vc.mfc)
  • Re: Problems with VariantChangeType and VT_BOOL
    ... This posting is provided "AS IS" with no warranties, and confers no rights. ... I have discovered that when I convert a BSTR to both VT_I4 or VT_BOOL ... Link in the library that contains the Variant functions. ... At this point a second thread will have been created. ...
    (microsoft.public.windowsce.app.development)
  • Re: Problems with VariantChangeType and VT_BOOL
    ... As far as I was aware the linker command in the pragma comment ... I have discovered that when I convert a BSTR to both VT_I4 or VT_BOOL ... Link in the library that contains the Variant functions. ... At this point a second thread will have been created. ...
    (microsoft.public.windowsce.app.development)
  • Re: Problems with VariantChangeType and VT_BOOL
    ... needs to tie into some sort of system notification should your system local ... I have discovered that when I convert a BSTR to both VT_I4 or VT_BOOL ... Link in the library that contains the Variant functions. ... At this point a second thread will have been created. ...
    (microsoft.public.windowsce.app.development)
  • Re: how to run EnableDHCP method in C++???
    ... EnableDHCP and EnableStatic work with C++. ... VARIANT arg3; arg3.vt = VT_ARRAY|VT_BSTR; arg3.parray = defgw_list; ... if(hres!= WBEM_S_NO_ERROR) ... BSTR ArgName1 = SysAllocString; ...
    (microsoft.public.win32.programmer.wmi)