PB/DLL passing multidimensional VB arrays by pointers 
Author Message
 PB/DLL passing multidimensional VB arrays by pointers

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
the pointer extension syntax to arrays(as the manual instructs) which goes like this:

example 1: sub test(BYVAL myarray as DWORD PTR, BYVAL n as integer ) export

Dim PtrMyarray as double PTR
Dim i%
DIM TestMatrix#(n%)
ptrMyarray = myarray

FOR i% = 0 to n% - 1

end sub

This works as long as i pass an ONE DIMENSIONAL array.
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
i've also tried this
.....

.. and this

--
but the compiler still comes up with the same error message.
is there any way so i can fill a two or more dimensional matrix as above described ?
If there is anybody out there that can help, do not hesitate to do so.

--
- Eigil Dingsoer



Sun, 27 Dec 1998 03:00:00 GMT  
 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.***



Mon, 28 Dec 1998 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Passing pointer to pointer to C struct from VB into a DLL

2. Passing pointer to a pointer or pointer to a char to a dll

3. Multidimensional, multidimensional arrays

4. how to pass a pointer to a pointer in a dll

5. Passing multidimensional arrays to subroutines

6. Passing MultiDimensional Array from ASP to VBScript

7. Passing array from VB to DLL and returning array

8. VB, C++ Builder and passing arrays and file pointers

9. Passing VB pointer to C Short Array (via void *)

10. Multidimensional Arrays, DLLs and CDK

11. Passing a pointer to a VB subroutine to a C DLL

12. Passing Vb pointers to Dlls

 

 
Powered by phpBB® Forum Software