Has anyone used SAFEARRAY ?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Has anyone used SAFEARRAY ?

Steve Geringer-3
Hi,

I need to create and pass a multi-dimensional SAFEARRAY as a parameter to a
DLL call.

It looks like creating a 1-dimensional array is pretty straighforward, but
how
do you create a mult-dimensional SAFEARRAY ?

any example code?

Thanks,
Steve Geringer


Reply | Threaded
Open this post in threaded view
|

Re: Has anyone used SAFEARRAY ?

Steve Geringer-3
ah-ha  i think i have solved the problem.. thought i would post it here for
the record
so no one else will have to go through this drudgery it took me to get
figured out


dolphin (at least v.3)  only supports single dimension safearrays

however, I found another call in OLEAut32.dll on the MSDN
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/automat/htm
_hh2/chap7_1rvp.asp


so I added the primitive to OLEAutLibrary as follows:

safeArrayCreate: vt cDims: cDims bounds: aSAFEARRAYBOUND

    "Create a multi-dimensional SAFEARRAY
    SAFEARRAY* SafeArrayCreate( VARTYPE vt, unsigned int cDims,
SAFEARRRAYBOUND * rgsabound );  "
    <stdcall: SAFEARRAY* SafeArrayCreate dword dword SAFEARRAYBOUND* >
    ^self invalidCall



then you use it as follows:
| safeArray  bound1 bound2 bound3  struct  |
bound1 :=  SAFEARRAYBOUND new  lLbound:  1; cElements: 30 .
bound2 :=  SAFEARRAYBOUND new  lLbound:  1; cElements: 30 .
bound3 :=  SAFEARRAYBOUND new  lLbound:  1; cElements: 1 .
struct := StructureArray length: 3 elementClass: SAFEARRAYBOUND .
struct at: 1 put: bound1.
struct at: 2 put: bound2.
struct at: 3 put: bound3.
safeArray := OLEAutLibrary default safeArrayCreate: DOUBLE vt cDims: 3
bounds: struct.
safeArray inspect.

of course the inspector assumes it is only one dimensional also, so it gives
an error if you try to inspect the values.  just ignore this error
to access elements at [10,10,1 ] code it as follows:

    safeArray elementAt: (Array with: 10 with: 10 with: 1)




"Steve Geringer" <[hidden email]> wrote in message
news:3d0802e6@tobjects....
>
> Hi,
>
> I need to create and pass a multi-dimensional SAFEARRAY as a parameter to
a

> DLL call.
>
> It looks like creating a 1-dimensional array is pretty straighforward, but
> how
> do you create a mult-dimensional SAFEARRAY ?
>
> any example code?
>
> Thanks,
> Steve Geringer
>
>
>
>