Announcement

Collapse
No announcement yet.

Passing Arrays to DLL from VB & PB

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

  • Passing Arrays to DLL from VB & PB

    Hello all,

    While I'm waiting for the coffee to engage my brain, I thought I'd pose the following:

    I'm writing a hardware I/O DLL in PB that will be used by both PB & VB 6. Some
    of these functions require that an array of DWORDs be passed back and forth. In
    the PB Help it shows how to pass the array from VB to PB:

    Code:
    SUB SortLong(BYVAL FirstElem AS LONG, Total AS LONG) EXPORT
    
      DIM A(1 to Total) AS LONG AT FirstElem
    
      ARRAY SORT A&()
    
    END SUB
    All well and good and I've used this method with VB before without difficulty.
    Can I also use this method when calling from PB? At first glance I would
    say yes, but since PB & VB use different array descriptors I'm not so sure.

    Thanks!

    ------------------
    Mark Newman
    Mark Newman

  • #2
    In this context, the array descriptors for the original array are not involved - the DLL code does not even know where they are stored, since you are passing the address of the array data itself, not the array descriptor.

    Remember, DIM..AT simply defines a new array at the memory address specified - effectively creating a new descriptor table just to handle that array.

    IOW, you can certainly use this technique with your PB code.

    However, if you want to create the array in PB and pass that to VB, then you'll have to find a different approach because VB does not support DIM..AT (at least, I've never heard that is does!).



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

    Comment


    • #3
      Thanks Lance!


      ------------------
      Mark Newman
      Mark Newman

      Comment


      • #4

        Mark,

        I have several examples if you are interested!

        MWM


        ------------------
        mwm
        mwm

        Comment


        • #5
          Michael,

          Thanks for the offer; I've used the overlay method fine with VB,
          I just wasn't sure if the same method was ok when calling from PB.


          ------------------
          Mark Newman
          Mark Newman

          Comment

          Working...
          X