Re: VBScript OCX receive and supply a safeArray of type VT_UI1- problem

"R.Wieser" <[email protected]>
Newsgroups alt.comp.os.windows-xp,alt.windows7.general,comp.os.ms-windows.programmer.win32
Organization A noiseless patient Spider
Message-ID <[email protected]>
Newyana2,

>   Variants have subtypes. But VBS only handles. An array is just a 
> collection of data packets in a row with an array descriptor prepended.
> Once you access a(x) you're accessing a data type. If that type is not a 
> variant then VBS can't use it.

I beg to differ again (exemptions-to-the-rule are the bane of most people 
:-) ).

My previously mentioned "method #1" returns a SafeArray of type VT_UI1, 
which in VBScript gets stored into a variant (which than shows its "vartype" 
as 0x2011 and its "typename" as "Byte()"(!) ).

I can "wscript.echo" and use use "len()" and "mid()" on it - though it does 
all of that badly, treating the VT_UI1 SafeArray as a BSTR. :-(

But yes, if I return a SafeArray of, for example, type VT_UI2 I cannot do 
anything with it - other than provide it to another OCX-based method.

... which was/is exactly what I was trying to do :-)

> The variant is a 16-byte package

:-) you're preaching to the choir.   I've been working with the internal 
makeup of Variants and looking into SafeArrays for quite a while now.

> If you declare Dim A2()

Which I have not done and, in the current case, have no intention to.  Any 
explanation in that direction is wasted energy.  Sorry.

> I assumed you were working in VB6, using VB6 strings.

Whut ?  I specifically mentioned VBScript in the subjectline and the first 
post, as well as thruout my replies ...

> A safearray is a variant. The data may be other datatypes.

No, it isn't.  What you are referring to is a Variant which contains (a 
pointer to) a SafeArray.

> I can then reference each character as an integer in the array, without 
> any string handling. It's just memory addresses, after all.
>
>  For i = 0 to UBound(ArrayThatsAString)
>   Select Case i

Are you trying to pull my leg ?   The only thing there you are using 
"ArrayThatsAString" for is to get its length.

Also, in VBScript that "ubound()" on a string doesn't work.  It *does* work 
on my VT_UI1 SafeArray-in-a-variant though. <huh!> :-)

> You can't do anything like that in VBS because each array member is always 
> a variant and there's no direct access to memory addresses,

In VBS you cannot access memory directly, ever.



But to return to my question:

it turns out that having the OCX-based method #1 return a SafeArray (as 
shown by the IDL in my first post) works without a problem.  The actual 
problem is that VBScript doesn't seem to understand how to do it the other 
way around.

Even though the IDL definition describes an SAFEARRAY(unsigned char) input 
to the OCX-based method #2 and VBSCript has a Variant of type "VT_ARRAY or 
VT_UI1" it can't seem to connect those dots.

This morning I've been trying several IDL definitions.  By value, by ref, as 
[in] and as [in,out], but none wanted to work. :-(

... and you know what the *real* weird thing is ?

That

Object.Method2( Object.Method1() )

(not using an intermediate variable I mean) *does* work.  How ?  Why ? No 
idea.

But ... I have a solution : Method #1 can keep returning a SafeArray, but I 
have to tell Method #2 to expect a Variant, and than just grab the pointer 
to the SafeArray from it.   Yes, an ugly work-around.  But for the moment it 
has to do.

Regards,
Rudy Wieser
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.