Announcement

Collapse
No announcement yet.

Passing Arrary and Types to Dlls by Ref

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

  • Passing Arrary and Types to Dlls by Ref

    How do I Declare an array in the calling .EXE and the DLL so that I can change array (or TYPE) values at either end ?

    Ie pass an array to a DLL that reads some fields and then adds some fields. Then have the added fileds available to the EXE that called the DLL.



    ------------------
    Kind Regards
    Mike

  • #2
    Variable types are fixed at compile time. There is no way to modify them at run time.
    You might consider other approaches, such as storing the data in variable-length
    strings or referring to elements by means of pointers. Interpreting the results is up
    to you.

    ------------------
    Tom Hanlin
    PowerBASIC Staff

    Comment


    • #3
      As Mr. Hanlin points out, you cannot change the data type or UDT definition once the program is compiled, but modifying the members of a UDT array should not be a problem:

      Code:
      #COMPILE EXE
      
      TYPE FooType
        member1 AS LONG
        member2 AS LONG
      END TYPE
      
      DECLARE FUNCTION UpdateFoo ALIAS "UpdateFoo" LIB "Foo.dll" (F () AS Footype) AS LONG
      
      FUNCTION WinMain (...
      
         REDIM Foo (100) AS Footype
      
         CALL UPdateFoo (Foo())
      
      END FUNCTION
      
      #COMPILE DLL "Foo.DLL"
      TYPE FooType
        member1 AS LONG
        member2 AS LONG
      END TYPE
      
      FUNCTION UpdateFoo (F () AS Footype) AS EXPORT AS LONG
      
         IF F(1).Member1 = 2 THEN
           F(1).Member2 = 5
         END IF
      
      ...
      END FUNCTION
      MCM




      ------------------
      Michael Mattias
      Racine WI USA
      [email protected]
      Michael Mattias
      Tal Systems (retired)
      Port Washington WI USA
      [email protected]
      http://www.talsystems.com

      Comment


      • #4
        Mike,

        As Tom pointed out, you cannot modify the udt construct
        at runtime. You'll need to determine the number of added
        elements for the udt at compile time. So just add the amount
        you'll need then let the dll do it's thing.

        An array, however can be resized (redimmed, oops). If you know
        what the base size is, then Redim for the added parts.

        One option for the udt approach would be to create a linked-list
        of structures (udts). If you know what I'm referring to, then
        the number of linked structures is up to you. Basically a
        linked-list is a udt with all the elements you require plus a
        pointer element to the next structure. That way you can track
        the list going and coming, add and delete as required.

        Cheers,
        Cecil

        ------------------

        Comment

        Working...
        X