Re: Confused about ATL and SafeArrays
From: Brian Muth (bmuth_at_mvps.org)
Date: 03/04/04
- Next message: Rami AlHasan: "SIP Proxy"
- Previous message: Mathew: "ATL Dialog Accelerators"
- In reply to: Richard Dixson: "Re: Confused about ATL and SafeArrays"
- Next in thread: Vi2: "Re: Confused about ATL and SafeArrays"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 3 Mar 2004 22:29:50 -0800
Richard, change your IDL to:
[id(1), HRESULT CheckNames([in] VARIANT Names, [out,retval] VARIANT
*Results);
and you'll find that
result = obj.CheckNames(Array("x", "y", "z"))
and
ArrayOfNames = Array("x", "y", "z")
result = obj.CheckNames(ArrayOfNames)
will work just fine. So will
dim name(4)
name(0) = "This"
name(1) = "is"
name(2) = "a"
name(3) = "test!"
result = obj.CheckNames(name)
In your server code, your Names parameter will be a VARIANT of type
(VT_ARRAY |VT_VARIANT), and you can get at the Safearray by accessing
Names.parray
Construct your returning Results value as a VARIANT of type (VT_ARRAY
|VT_VARIANT), indicating a safearray of VARIANT's, and each VARIANT is of
type VT_BOOL.
Brian
and construct your
"Richard Dixson" <please@replyhereonly.com> wrote in message
news:kLedndxnm6J-PtvdRVn-gw@comcast.com...
> > > Question 2: Why does changing it from SAFEARRAY(BSTR) to
> > > SAFEARRAY(VARIANT) then let me call it using the Array function, but
> > > still not pass it in as an array (i.e. CheckNames(name))?
> >
> > Try declaring the name as
> > dim name()
> >
> > that is, without specifying bounds.
>
> Unfortunately that didn't work. I changed the IDL to SAFEARRAY(VARIANT).
> Then from ASP I tried:
> dim name()
> redim name(4)
> name(1) = "xxx"
> ...
> result = obj.CheckNames(name)
>
> But when calling CheckNames I still get the vbscript type mismatch error,
> just like it did when I had dim name(4).
>
> The only way I can call the method from ASP is:
> result = obj.CheckNames(Array("x", "y", "z"))
>
> Interestingly I cannot do the following either because I also get the type
> mismatch error:
> ArrayOfNames = Array("x", "y", "z")
> result = obj.CheckNames(ArrayOfNames)
>
> Any other suggestions you can think of?
>
> >
> > Are you still declaring pNamesdata as BSTR*? Remember, you now have a
> > SAFEARRAY of VARIANTs, so pNamesdata should be declared as VARIANT*. The
> > actual BSTR is at pNamesdata[i].bstrVal
>
> Yes, that was the problem. However I noticed I was getting the wrong
string
> value (weird!) when using pNamesdata[i].bstrVal. Instead I'm using the
> following code to retrieve each value, and it works:
> V_BSTR(&pNamesdata[i])
>
> Why does that work but referencing it your style with .bstrVal does not?
>
> *** Main problem now ***
>
> OK, I'm not mostly there. But there is one significant issue... I cannot
> get ASP to access the return array of booleans :(
>
> When I do this:
> result = obj.CheckNames(Array("x", "y", "z"))
>
> And then from ASP try:
> Response.Write result(1)
>
> I get a "type mismatch" vbscript error from ASP on that line! Inside the
> C++ code I watched it set 4 elements to VARIANT_TRUE and VARIANT_FALSE.
And
> also from ASP IsArray(abc) does return True! So its as if it recognizes
it
> as an array but it will not let me access its members without a type
> mismatch error.
>
> What do you make of this? What can I try? Thank you so very much for all
> your help. With this last issue solved I will basically be as far as I
need
> to get the basics working.
>
> Richard
>
>
- Next message: Rami AlHasan: "SIP Proxy"
- Previous message: Mathew: "ATL Dialog Accelerators"
- In reply to: Richard Dixson: "Re: Confused about ATL and SafeArrays"
- Next in thread: Vi2: "Re: Confused about ATL and SafeArrays"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|