Announcement

Collapse
No announcement yet.

Passing Multi-Dimensional Arrays Between PBDLL and VB6

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Passing Multi-Dimensional Arrays Between PBDLL and VB6

    I am trying to pass a 2D VB array of doubles to a PBDLL SUB that
    sums each row. I keep getting an error that "The object invoked
    has disconnected from it's clients."

    Here is an example that illustrates the problem. Anyone know what
    is wrong?

    Thanks,

    Gene


    SUB SumArray ALIAS "SumArray" (a AS DWORD, r AS DWORD) EXPORT

    ' sum each row in the 2D array "a"
    ' and return the results in array "r"

    REGISTER sum AS EXT
    REGISTER row AS LONG
    REGISTER col AS LONG
    DIM vb AS DWORD
    DIM rows AS LONG
    DIM cols AS LONG

    rows = vbArrayUBound(a, 1)
    cols = vbArrayUBound(a, 2)

    vb = vbArrayFirstElem(a)
    DIM a(1 TO rows, 1 TO cols) AS DOUBLE AT vb

    vb = vbArrayFirstElem(r)
    DIM r(1 TO rows) AS DOUBLE AT vb

    FOR row = 1 TO rows
    sum = 0.0
    FOR col = 1 TO cols
    sum = sum + a(row,col)
    NEXT col
    r(row) = sum
    NEXT row

    END SUB

    ------------------
    Gene

  • #2
    Assuming you are passing the array descriptor from VB (you did not post the VB code), the PB code should be receiving the DWORD BYVAL, since you want to get the address of the array descriptor that VB is passing to PB.

    Without the BYVAL DWORD in the PB code, PB is taking the actual value in the memory within the descritor and treating it as the address of the descriptor table.

    Try this:

    SUB SumArray ALIAS "SumArray" (BYVAL a AS DWORD, BYVAL r AS DWORD) EXPORT

    ------------------
    Lance
    PowerBASIC Support
    mailto:[email protected][email protected]</A>
    Lance
    mailto:[email protected]

    Comment


    • #3
      Thanks for the info, I tried your suggestion
      but it didn't work.

      I am going by the vb sort examples,
      vbsort.bas and vbsort.txt that come with PB.

      The sorting function examples work fine without using byval.
      If you have an example of passing a 2D array to/from VB and
      PB it would be greatly appreciated.

      Thanks.

      Here is all the code from vb (I'm using excel to test):

      Declare Sub SumArray Lib "vbsort.dll" (a#(), r#())

      Private Sub CommandButton3_Click()

      Dim i As Long
      Dim ii As Long
      Dim a(1 To 10, 1 To 5) As Double
      Dim r(1 To 10) As Double

      For i = 1 To 10
      For ii = 1 To 5
      a(i, ii) = i * ii
      Next
      Next

      SumArray a(), r() ' error!!!

      For i = 1 To 10
      Sheet1.Cells(i, 1).Value = r(i)
      Next

      End Sub

      ------------------
      Gene

      Comment


      • #4
        This should help!
        Code:
        Declare Sub SumArray Lib "vbsort.dll" [b]Alias "SumArray"[/b] (a#(), r#())
        ------------------
        Tom Hanlin
        PowerBASIC Staff

        Comment


        • #5
          I tried adding Alias "SumArray" as above, but since the
          alias and the sub have the same name, the vb editor
          deletes the alias statement, putting it back to this:

          Declare Sub SumArray Lib "vbsort.dll" (a#(), r#())

          I can run the vbsort.bas SortDouble example fine with the
          following declaration:

          Declare Sub SortDouble Lib "vbsort.dll" (x#())

          It seems to be a problem with the 2D array. Does anyone have an
          example of passing a 2D array to/from vb/pbdll?

          Thanks.

          ------------------
          Gene

          Comment


          • #6
            gene --
            i very recommend borje's poffs, which has nice search capabilities.
            during 5 sec i found http://www.powerbasic.com/support/pb...ead.php?t=2369

            ------------------
            e-mail: [email protected]

            Comment

            Working...
            X