
PB/DLL passing multidimensional VB arrays by pointers
Quote:
> hello !
> i'm a user of PB/DLL v.1.01. I use it in connection with VB and VBA in Excel 5.0.
> now i've encountered a problem(at least to me).
> I want to send VB created arrays to the compiled DLL for further number crunching and i want to use
(snip)
> the pointer extension syntax to arrays
> what i want to do is to fill a TWO DIMENSIONAL or more array using the same kind of syntax, but the
> compiler states " undefined sub/function" when i try to do the following.
> example 2: sub test(BYVAL myarray as DWORD PTR, BYVAL n as integer ) export
> Dim PtrMyarray as double PTR
> Dim i%, j%, k%
> K% = 5
> DIM TestMatrix#()'1 based
> REDIM testmatrix#(n%, k%)
> ptrMyarray = myarray
> FOR i% = 0 to n% - 1
> FOR j% = 0 to k% - 1
> end sub(snip)
> is there any way so i can fill a two or more dimensional matrix as above described ?
You cannot use PB's square bracket array pointer [i, j] syntax for arrays that you pass
from VB---it only gives the correct pointer for arrays DIMed within the DLL.
You CAN work with VB multidimensional arrays, but you must do some work yourself. PB/DLL
treats all arrays passed from VB as though they are one-dimensional. Therefore you
need to figure out where in the linear address space a given element is stored within
the VB array.
For a 2-dimensional (row, column) matrix, VB first stores all the elements of the first
column in ascending row #, then all the elements of the 2nd column, etc.
Thus if you have an N x M array in VB (zero based) your test2 code would look like:
What this also means is that the DLL code must know the dimensions of the VB array (or,
at least, the second dimension of a 2-dimensional array), so if the dimensions are always
the same you can hard code them into the .DLL code or pass the dimensions to the .DLL and
use it as the multiplier (M in my example above) to calculate the equivalent linear array
element index.
'Hope this helps.
John Philo, Protein Chemistry
Amgen Inc., Thousand Oaks, CA
*** Disclaimer: These are the opinions of the poster not Amgen Inc.***