No announcement yet.

Passing arrays from VB to PB

  • Filter
  • Time
  • Show
Clear All
new posts

  • Passing arrays from VB to PB

    I've searched the forum, but haven't found an answer.
    Could someone please tell me how to pass a 1d array of longs from VB to PB?
    (the PB/DLL 6.0 help file example didn't work - dim array(1 to 20) at firstelement).
    Also, how do I pass an array of UDT from VB to PB?
    This is assuming the UDT is composed solely of long vars, so, there is no padding problems.



  • #2
    See Appendix B in the help file for information on VB arrays and PB/DLL.

    Essentially you either need to pass the address of the 1st element to the DLL or you can pass the descriptor and use the vbArrayFirstElem() (and related) functions in VBAPI32.INC. The former is the easiest method in most cases.

    For example, pass an array of LONG integers from VB to PB simply by passing the 1st element of the array from VB by reference, and receive the address as a DWORD by value (ie, "BYVAL ArrAddress AS DWORD"). Then use "DIM LongIntArr(params) AS LONG AT ArrAddress" to position the PB array 'over the top' of the VB array.

    With UDT's, it is more complicated than numeric arrays, simply because VB uses a technique called "Natural Alignment" which is *similar* to DWORD alignment. By default PB/DLL uses BYTE alignment, and often the equivalent PB/DLL UDT structure must contain additional "padding" (dummy bytes) to ensure that the data can be positioned inside the UDT structure correctly when it is passed to/from VB. An overview of the process of converting VB structures to PB/DLL is also discussed in Appendix B of the help file.

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


    • #3
      I have corrected the problem thanks to you. (forgot to pass first element BYREF in VB)

      Many thanks.

      Alvaro Cardoso